Page 1 of 1

sum total in a query with group by used

Posted: Fri Jun 17, 2005 3:26 am
by rsmarsha
I have the following query:

Code: Select all

$ref2 = "SELECT DATE_FORMAT(dateadded, '%d-%m-%Y') AS dateadded,COUNT(refer) AS refno,refer,status FROM orders $filter $date GROUP BY refer ORDER BY refno DESC";
Is there a way to find the sum total of "refer" using the same query?

At present i'm pulling out all a count of "refers" grouped together in sets, but i also need an overall count of those found in the above query.

Posted: Sat Jun 18, 2005 10:55 am
by dreamline
How about a mysql_num_rows($result) that gives you the total rows found. :)

Posted: Sat Jun 18, 2005 2:53 pm
by John Cartwright

Code: Select all

$ref2 = "SELECT DATE_FORMAT(`dateadded`, '%d-%m-%Y') AS `dateadded`,COUNT(`refer`) AS `refno`, SUM(`refer`) as `sum`, refer,`status` FROM `orders` $filter $date GROUP BY `refer` ORDER BY `refno DESC`";