Skip to main content
Inspiring
July 11, 2007
Question

Counting the Total

  • July 11, 2007
  • 1 reply
  • 237 views
i am doing testing on a application where i count the ads based on sessions here is the query;

SELECT count(classified.classifiedID) as cAds, classified.ccat
FROM classified where postedby = '#session.user.username#'
GROUP BY ccat

well if i have two different categories, it show me as the results in the output window as 21 means 2 records of category ASA and 1 record of category BSB

it does not show me the total records for the specific logged in user.

and below i am geeting like:

total records: 21 records

2 for ASA
1 for BSB

but i want it like;

total records: 3 records

2 for ASA
1 for BSB

hope u guys understood...

is something wrong in query or should i use ike SUM function of SQL or whatever
    This topic has been closed for replies.

    1 reply

    Participating Frequently
    July 11, 2007
    Hard to put it all in one query. Why don't you just add up the cAds in the output?

    <cfset cSum = 0>
    <cfloop query = "your_query>
    <cfset cSum = cSum + cAds>
    </cfloop>
    <cfoutput>#cSum#</cfoutput>

    Phil
    Inspiring
    July 11, 2007
    quote:

    Originally posted by: paross1
    Hard to put it all in one query. Why don't you just add up the cAds in the output?

    <cfset cSum = 0>
    <cfloop query = "your_query>
    <cfset cSum = cSum + cAds>
    </cfloop>
    <cfoutput>#cSum#</cfoutput>

    Phil

    Two other ways to accomplish this are:
    YourSum = arraysum(YourQuery["cAds"]);

    or a Q of Q
    select sum(cads) as YourSum
    from YourQuery