Skip to content

Instantly share code, notes, and snippets.

@williamjacksn
Last active December 24, 2015 02:19
Show Gist options
  • Save williamjacksn/6729374 to your computer and use it in GitHub Desktop.
Save williamjacksn/6729374 to your computer and use it in GitHub Desktop.
WITH
rated_songs AS (
SELECT song_rating_id
FROM rw_songratings
WHERE user_id = %s),
unrated_songs AS (
SELECT song_id, album_id, song_available, song_releasetime
FROM rw_songs
WHERE song_verified AND sid = %s AND song_rating_id NOT IN (
SELECT song_rating_id FROM rated_songs)),
album_unrated_counts AS (
SELECT album_id, COUNT(song_id) AS unrated_songs_in_album
FROM rw_songs
WHERE song_id IN (
SELECT song_id FROM unrated_songs)
GROUP BY album_id)
SELECT song_id, album_id, song_available, song_releasetime, unrated_songs_in_album
FROM unrated_songs
JOIN album_unrated_counts USING (album_id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment