FlimFlam FlimFlam - 2 years ago 111
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;



Answer Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download