Created
November 7, 2016 02:16
-
-
Save iAmWillShepherd/2515f9f8b97ae2a31fdf79a1f7e6c16f to your computer and use it in GitHub Desktop.
This file contains 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
SELECT | |
data.name | |
, data.stars AS avgStars | |
, data.numberOfReviews | |
, (cool / totalVotes) AS `% cool` | |
, (useful / totalVotes) AS `% useful` | |
, (funny / totalVotes) AS `% funny` | |
FROM ( | |
SELECT | |
b.business_id | |
, b.stars | |
, b.name | |
, count(r.business_id) AS numberOfReviews | |
, sum(r.votes_cool) AS cool | |
, sum(r.votes_useful) AS useful | |
, sum(r.votes_funny) AS funny | |
, sum(r.votes_cool + r.votes_funny + r.votes_useful) AS totalVotes | |
FROM business AS b | |
INNER JOIN review AS r ON | |
b.business_id = r.business_id | |
GROUP BY b.business_id) AS data | |
ORDER BY numberOfReviews DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment