Reputation: 29
Hello not sure if this is possible in mysql but I've got a table like:
Value ¦ Name
1 ¦ Bob
3 ¦ Bob
5 ¦ Paul
3 ¦ Bob
7 ¦ Paul
Is there a way to select all of bob's values add them up, select all of Pauls values add them up then output who's value is the highest? The database has multiple names and hundreds of values.
Any help would be great thank you! I'm able to use PHP if this would make this task easier!
Upvotes: 1
Views: 39
Reputation: 17289
http://sqlfiddle.com/#!9/fddbf/1
SELECT SUM(t.val) val_sum,t.name
FROM table1 t
group by name
order by val_sum desc
LIMIT 1
Upvotes: 3