This query should work:
SELECT name, SUM(amount) as total FROM user_amounts GROUP BY name ORDER BY total DESC LIMIT 1
Explanation:
I'll explain how you should write your queries, or at least how to solve next time.
First start with a simple select of names and amounts:
SELECT name, amount FROM user_amounts
Then we want to know amount of every name, so we have this query:
SELECT name, SUM(amount) as total FROM user_amounts GROUP BY name
As you can see i used SUM
function and GROUP BY
because if you don't use GROUP BY name
then your result will be only one row.
After that we have something like this
joh 200
cathy 150
phyo 400
But we want the first the higher ammouunt, so need to order it, and we only want the higher, so limit 1 to only recover the first name
SELECT name, SUM(amount) as total FROM user_amounts GROUP BY name ORDER BY total DESC LIMIT 1
Hope it'll be clear.