I know this should be easy but it’s just not my day today.
I have a table like this
user | points
---------|------------
Smith | 100
Neo | 200
Morpheus | 300
Smith | 100
Neo | 200
Morpheus | 300
and the select I’m looking for would produce this
user | points
---------|------------
Morpheus | 600
Neo | 400
So, I would like to print out the users who have more than 300 points total and i would like to print them out sorted by sum from highest to lowest.
I’m using:
$ mysql -V
mysql Ver 14.14 Distrib 5.1.61, for redhat-linux-gnu (x86_64) using readline 5.1
The SQL I’ve been trying is this:
SELECT user, SUM(points) AS sum FROM users GROUP BY user HAVING SUM(points)>300
and this gives me all the correct output, though it doesn’t give me sorted output. And I did try inserting the ORDER BY but to no luck.
1 Answer