|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
I'm doing a group by statement in MySQL, heres some example data.
Name Age White 20 Black 17 White 22 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. |
|
#2
|
|||
|
|||
|
Your SQL should be:
SELECT name, SUM(age) FROM <table_name> 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. |
![]() |
| Viewing: Dev Shed Forums > Databases > MySQL Help > Grouping By |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|