FlimFlam FlimFlam - 1 year ago 78
MySQL Question

Group By and Order By in query

I'm trying to work the total prize money for each of several events. I want to sort the results by total prize money, however this does not seem to be working. I'm only able to group by event, or order by total money (which just gives me the total of the money column).

Here's the query and table:

SELECT event_id, SUM(money) as 'total money'
FROM prize
GROUP by event_id
ORDER by 'total money' desc;




As @juergen d said, this will help you.

SELECT event_id, SUM(money) as `total money`
FROM prize 
GROUP by event_id  
ORDER by `total money` desc;