Skip to content

Instantly share code, notes, and snippets.

@polomarcus
Created March 2, 2017 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save polomarcus/5868f1009b8361711dd556fda1de4890 to your computer and use it in GitHub Desktop.
Save polomarcus/5868f1009b8361711dd556fda1de4890 to your computer and use it in GitHub Desktop.
SQL - Percentage and GROUP BY
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