July 25th, 2000, 06:33 AM
I'm doing a group by statement in MySQL, heres some example data.
SELECT * FROM [tblname] GROUP BY Name.
When I do this group by statement, the statement returns the average of the ages rather than the sum of which is need. Do I need to do a loop to get each name and add the total, or is there another way of doing it...by using the SUM statement for example.
July 28th, 2000, 08:48 AM
Your SQL should be:
SELECT name, SUM(age)
GROUP BY name;
MySQL just chose AVE for you as the default aggregate function to apply to the non-grouped column -- if you want it to do something different, you have to explicitly tell it so.