Last active
October 28, 2021 20:56
-
-
Save tpinto/370582b4716649bdd43c9c4201b570bb to your computer and use it in GitHub Desktop.
livecode.sql
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
-- forgot to save the first one. sorry about that | |
SELECT t.name, t.composer | |
FROM tracks t | |
JOIN playlist_tracks pt ON pt.track_id = t.id | |
JOIN playlists p ON pt.playlist_id = p.id | |
WHERE p.name = 'Classical' | |
LIMIT 10; | |
SELECT a.name, COUNT(*) AS count | |
FROM artists a | |
JOIN albums ON albums.artist_id = a.id | |
JOIN tracks t ON t.album_id = albums.id | |
JOIN playlist_tracks pt ON pt.track_id = t.id | |
GROUP BY a.name | |
ORDER BY count DESC | |
LIMIT 10; | |
SELECT t.name, artists.name, COUNT(*) AS purchases | |
FROM tracks t | |
JOIN albums ON t.album_id = albums.id | |
JOIN artists ON albums.artist_id = artists.id | |
JOIN invoice_lines il ON il.track_id = t.id | |
GROUP BY t.id | |
HAVING purchases >= 2 | |
ORDER BY purchases DESC | |
LIMIT 10; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment