Link to home
Start Free TrialLog in
Avatar of detox1978
detox1978Flag for United Kingdom of Great Britain and Northern Ireland

asked on

MySQL count query help

Hi All,

I have a MySQL table where users have rated movies 1-5.  I want to get a summary of how  man 1,2,3,4 & 5's they have voted for.

I can get the answer for a single rating, below

SELECT COUNT(rating) AS "1 Star" FROM user_likes WHERE user_id=2 AND rating=1

Is it possible to get them all at in one go?
ASKER CERTIFIED SOLUTION
Avatar of Randy Poole
Randy Poole
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of detox1978

ASKER

Excellent thanks
Avatar of Nathan Riley
select count(rating) AS NumofVotes, rating
from user_likes WHERE user_id=2
group by rating
order by rating desc

Open in new window