Skip to content

Commit

Permalink
Added artist statistics report file
Browse files Browse the repository at this point in the history
  • Loading branch information
davewalker5 committed Nov 13, 2023
1 parent d10c25b commit 9fbacb7
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
18 changes: 18 additions & 0 deletions src/MusicCatalogue.Logic/Sql/ArtistStatistics.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 ) = $wishlist
GROUP BY a.Id, a.Name
ORDER BY a.Name ASC
27 changes: 18 additions & 9 deletions src/MusicCatalogue.Logic/Sql/GenreStatistics.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
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 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 = $wishlist
GROUP BY Genre
ORDER BY Genre ASC;
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 = $wishlist
GROUP BY Genre
ORDER BY Genre ASC;
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 9fbacb7

Please sign in to comment.