Created
January 11, 2012 14:35
-
-
Save samflores/1594936 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Number of restaurants with 5, 4, 3, 3, 1 and 0 average ratings | |
SELECT stars_avg, count(stars_avg) | |
FROM ( | |
SELECT FLOOR(AVG(r.stars)) AS stars_avg | |
FROM rates AS r | |
JOIN venues AS v ON v.id = r.rateable_id | |
JOIN types AS t ON t.id = v.type_id | |
WHERE t.name = "Restaurants" | |
AND r.rateable_type = "Venue" | |
GROUP BY v.id) AS star_avgs_tbl | |
GROUP BY stars_avg | |
ORDER BY stars_avg DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment