4 Replies Latest reply on Dec 5, 2006 7:58 PM by MikerRoo

    Sum Loop over Group

    Ling0 Level 1
      Hi,

      I am trying to group a query and loop over and output hours summed. I attached the caode and an image of the results.
      Any help will be greatly appreciated.
      Thank you,
      -R
        • 1. Re: Sum Loop over Group
          Dan Bracuk Level 5
          Do you know how to select aggregates, such as count, sum, min, max, and avg in sql? All that works either in your original query, or with query of queries.
          • 2. Re: Sum Loop over Group
            MikerRoo Level 1
            The second sum is off because the counter is initialized in the wrong place.

            Move <CFSET counter = 0> to just before the second <CFOUTPUT> tag.

            Then get rid of these lines:

            <CFLOOP QUERY="project_hours" STARTROW="#NewCount#" ENDROW="#CURRENTROW#">
            <CFSET counter = counter + #Hours#>
            </CFLOOP>

            • 3. Re: Sum Loop over Group
              Ling0 Level 1
              Thank you MikerRoo - As soon as I read your message it made perfect sense. The sum of total hours across all projects works - I am multiplying the rate X Hours and I get the Project totals and this works However I am trying to sum all of the Project totals and this is not working.

              The total should be 4375 however it is returning 3140 it is off by 1235. Any help would be greatly appreciated.
              • 4. Re: Sum Loop over Group
                MikerRoo Level 1

                Forget about the array math.

                Use this kind of logic: