Currently Being Moderated
Jun 8, 2006 5:30 PM
I have a table with 5 columns:
id | provider | referrer | pt_count | address1
I'm trying to create a report page which groups by address1,
creates a sum total of the pt_count for all address1 records, then
displays a list of all referrers, then a list of all providers
associated with address1.
I am able to group the address1 results and get the sum total
of the pt_count for each address1 with the following SELECT
statement:
<CFQUERY name="tuccreport" datasource="#myDB#"
dbtype="ODBC">
SELECT DISTINCT address1, SUM(pt_count) AS Total_Patients,
referrer, provider
FROM tucc_final
GROUP BY address1
ORDER BY Total_Patients desc
</cfquery>
When I output the results:
<CFSET myCounter="1">
<CFOUTPUT query="tuccreport" GROUP="address1">
<tr>
<td id="data0" valign="top">#myCounter#</td>
<td id="data1" valign="top">#address1#</td>
<td id="data2" valign="top">#Total_Patients#</td>
<td id="data3" valign="top"></td>
<td id="data4" valign="top"></td>
</tr>
<CFSET myCounter=(#myCounter#+1)>
</CFOUTPUT>
I get a table with a counter, then the first two fields just
as I want them: An address, then a sum total of the pt_count field
for all instances of that address.
Now all I need to do is add the groups of referrer and
providers, and I'm done. But as soon as I change the query to:
<CFQUERY name="tuccreport" datasource="#myDB#"
dbtype="ODBC">
SELECT DISTINCT address1, SUM(pt_count) AS Total_Patients,
referrer, provider
FROM tucc_final
GROUP BY address1, referrer
ORDER BY Total_Patients desc
</cfquery>
The results start getting broken down. My address group is
still getting some sort of partial total, but it is broken down so
it appears spread out over multiple rows in the report table.
Same thing happens if I add "provider" to the Group By, it
breaks the results down even further. There is still grouping going
on based on Address1, but the Address1 group appears to be getting
broken into chunks somehow.
Any ideas?
Thanks,
max