MySQL count query help

Posted on 2014-07-14
Last Modified: 2014-07-14
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?
Question by:detox1978
    LVL 21

    Accepted Solution

    SELECT COUNT(rating) AS num,rating FROM user_likes WHERE user_id=2  group by rating
    LVL 2

    Author Closing Comment

    Excellent thanks
    LVL 11

    Expert Comment

    by:N R
    select count(rating) AS NumofVotes, rating
    from user_likes WHERE user_id=2
    group by rating
    order by rating desc

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now