Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

cfoutput group by

Explorer ,
Nov 29, 2011 Nov 29, 2011

Hi, my report is similar to the table below.  I need to to get the total of each state but my query didn't work, can you please help !!

StateCost
TX125
TX500
Totaltotal of TX
MO100
MO215
Totaltotal of Mo
CA500
Totaltotal of CA

<cfoutput query="getall">

     <cfset subtotal = 0 />

     <tr>

          <td>#state#</td>

          <td>#amount</td>

     </tr>

     <tr>

          <cfoutput group ="sate">

               <cfset subtotal = subtotal + amount />

          </cfoutput>

          <td>#subtotal#</td>

     </tr>

</cfoutput>

thanks

810
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 30, 2011 Nov 30, 2011
LATEST

Try this:

<cfparam name="total_cost" default="0">

<cfquery name="qname" datasource="dsn">

SELECT state

     , amount

FROM tablename

ORDER BY state

</cfquery>

<table border="1">

<cfoutput query="qname" group="state">

   <cfoutput>

   <tr><td>#state#</td><td>#amount#</td></tr>

   <cfset total_cost = total_cost + amount>

   </cfoutput>

<tr><td>Total #state#</td><td>#total_cost#</td></tr>

<cfset total_cost = 0>

</cfoutput>

</table>

You needed a second (blank) cfoutput nested within the first, with the group attrib on the first because the first one just loops through the states.  The second one loops through the amounts within each state.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources