Created
March 2, 2017 17:00
-
-
Save polomarcus/5868f1009b8361711dd556fda1de4890 to your computer and use it in GitHub Desktop.
SQL - Percentage and GROUP BY
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 ROUND( (COUNT(t.*) / subTotal.total_radio * 100),2) AS percentage_of_songs, | |
subTotal.total_radio, | |
ROUND(popularity / 10) * 10 AS popularity, | |
t.radio | |
FROM AudioFeatureArtistTrackRadios t | |
JOIN ( | |
SELECT COUNT(*) AS total_radio, radio | |
FROM AudioFeatureArtistTrackRadios | |
GROUP BY radio | |
) AS subTotal | |
ON subTotal.radio = t.radio | |
GROUP BY subTotal.total_radio, ROUND(popularity / 10) * 10, t.radio | |
ORDER BY popularity |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment