Reputation: 75
Is there a simple query to achieve the following?
I have the following table:
ID RATING
1 1
2 2
3 5
4 5
I need to get the percentages of each rating like this
1 25
2 25
5 50
Upvotes: 1
Views: 371
Reputation: 1856
Following code will be helpful to you,
SELECT RATING, (COUNT(*) / (SELECT COUNT(*) FROM your_table)) * 100 AS Percentage
FROM your_table
GROUP BY RATING;
Upvotes: 4