Skip to content

Instantly share code, notes, and snippets.

@Haumer
Created July 23, 2020 16:56
Show Gist options
  • Select an option

  • Save Haumer/2f8f11df1ca097d5e5dbc3610272cdec to your computer and use it in GitHub Desktop.

Select an option

Save Haumer/2f8f11df1ca097d5e5dbc3610272cdec to your computer and use it in GitHub Desktop.
# Customer list
SELECT first_name, last_name, email FROM customers
ORDER BY last_name
# Classical Playlist
SELECT tracks.name, tracks.composer FROM playlist_tracks
JOIN tracks ON tracks.id = playlist_tracks.track_id
JOIN playlists ON playlists.id = playlist_tracks.playlist_id
WHERE playlists.name = "Classical"
# Top 10 artists in Playlists
SELECT artists.name, COUNT(*) AS occurances FROM artists
JOIN albums ON albums.artist_id = artists.id
JOIN tracks ON tracks.album_id = albums.id
JOIN playlist_tracks ON playlist_tracks.track_id = tracks.id
GROUP BY artists.name
ORDER BY occurances DESC
LIMIT 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment