Skip to content

Commit

Permalink
Re-added SQL scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
davewalker5 committed Nov 13, 2023
1 parent 9fbacb7 commit 38e3339
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sql/List Albums by Artist.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT al.Title, ar.Name, al.Genre, al.Released, al.CoverUrl
FROM ARTISTS ar
INNER JOIN ALBUMS al ON al.ArtistId = ar.Id
WHERE ar.Name = 'The Beatles'
ORDER BY al.Title ASC;
3 changes: 3 additions & 0 deletions sql/List Artists.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT ar.Name
FROM ARTISTS ar
ORDER BY ar.Name ASC;
7 changes: 7 additions & 0 deletions sql/List Tracks for Album.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SELECT DISTINCT al.Title, ar.Name, t.Number, t.Title, strftime('%M:%S', (t.Duration / 1000), 'unixepoch') AS "Duration"
FROM ARTISTS ar
INNER JOIN ALBUMS al ON al.ArtistId = ar.Id
INNER JOIN TRACKS t ON t.AlbumId = al.Id
WHERE ar.Name = 'The Beatles'
AND al.Title = 'The Beatles'
ORDER BY t.Number ASC;
18 changes: 18 additions & 0 deletions sql/Summarise By Artist.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
WITH ARTIST_SPEND ( Id, Spend ) AS
(
SELECT al.ArtistId, SUM( al.Price )
FROM ALBUMS al
GROUP BY al.ArtistId
)
SELECT a.Id,
a.Name,
COUNT( DISTINCT al.Id ) AS "Albums",
COUNT( DISTINCT t.Id ) AS "Tracks",
asp.Spend AS "Spend"
FROM ARTIST_SPEND asp
INNER JOIN ARTISTS a ON a.Id = asp.Id
INNER JOIN ALBUMS al ON al.ArtistId = a.Id
INNER JOIN TRACKS t ON t.AlbumId = al.Id
WHERE IFNULL( al.IsWishListItem, 0 ) = 0
GROUP BY a.Id, a.Name
ORDER BY a.Name ASC
12 changes: 12 additions & 0 deletions sql/Summarise By Genre.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
WITH ALBUM_SUMMARY ( Id, ArtistId, Genre, Tracks, Price, IsWishListItem ) AS
(
SELECT a.Id, a.ArtistId, a.Genre, COUNT( t.Id ), IFNULL( a.Price, 0 ), IFNULL( a.IsWishListItem, 0)
FROM ALBUMS a
INNER JOIN TRACKS t ON t.AlbumId = a.Id
GROUP BY a.Id, a.ArtistId, a.Genre, a.Price
)
SELECT Genre, COUNT( DISTINCT ArtistId) AS "Artists", COUNT( DISTINCT Id ) AS "Albums", SUM( Tracks ) AS "Tracks", SUM( Price ) AS "Spend"
FROM ALBUM_SUMMARY
WHERE IsWishListItem = 0
GROUP BY Genre
ORDER BY Genre ASC;

0 comments on commit 38e3339

Please sign in to comment.