SQL Music Project

Using a Billboards dataset of music, I asked the questions:
How many purchases by genre?
SELECT g.name, count(*)
FROM Invoice
JOIN InvoiceLine
ON Invoice.InvoiceId = InvoiceLine.InvoiceId
JOIN Track
ON InvoiceLine.TrackId = Track.TrackId
JOIN Genre AS g
ON g.GenreId = Track.GenreId
GROUP BY g.name;
What media type was purchased?
SELECT mt.name, count(DISTINCT c.customerId) as Purchased
FROM InvoiceLine
JOIN Track
ON InvoiceLine.TrackId = Track.TrackId
JOIN MediaType AS mt
ON Track.MediaTypeId = mt.MediaTypeId
JOIN Invoice
ON Invoice.InvoiceId = InvoiceLine.InvoiceId
JOIN Customer AS c
ON c.CustomerId = Invoice.CustomerId
GROUP BY mt.name;
SELECT g.name, count(*)
FROM Invoice
JOIN InvoiceLine
ON Invoice.InvoiceId = InvoiceLine.InvoiceId
JOIN Track
ON InvoiceLine.TrackId = Track.TrackId
JOIN Genre AS g
ON g.GenreId = Track.GenreId
GROUP BY g.name;
SELECT mt.name, count(DISTINCT c.customerId) as Purchased
FROM InvoiceLine
JOIN Track
ON InvoiceLine.TrackId = Track.TrackId
JOIN MediaType AS mt
ON Track.MediaTypeId = mt.MediaTypeId
JOIN Invoice
ON Invoice.InvoiceId = InvoiceLine.InvoiceId
JOIN Customer AS c
ON c.CustomerId = Invoice.CustomerId
GROUP BY mt.name;
Top 10 artists by sales?
SELECT *
FROM(select ar.name as artist_name, count(t.trackid) as popular
FROM invoice i
JOIN invoiceline il
ON i.invoiceid = il.InvoiceId
JOIN customer c
ON c.customerid = i.customerid
JOIN track t
ON t.trackid = il.TrackId
JOIN album a
ON a.albumid = t.AlbumId
JOIN Artist ar
ON ar.artistid = a.artistid
GROUP BY ar.name) sub
ORDER BY popular DESC
LIMIT 10;
SELECT *
FROM(select ar.name as artist_name, count(t.trackid) as popular
FROM invoice i
JOIN invoiceline il
ON i.invoiceid = il.InvoiceId
JOIN customer c
ON c.customerid = i.customerid
JOIN track t
ON t.trackid = il.TrackId
JOIN album a
ON a.albumid = t.AlbumId
JOIN Artist ar
ON ar.artistid = a.artistid
GROUP BY ar.name) sub
ORDER BY popular DESC
LIMIT 10;
Money Spent VS Number of tracks sold.
SELECT i.billingcountry AS Country, ROUND(SUM(iv.unitprice * iv.quantity),2) AS Sales, COUNT(t.trackid) AS No_Tracks
FROM Invoice i
JOIN InvoiceLine iv
ON i.invoiceid = iv.invoiceid
JOIN track t
ON t.trackid = iv.trackid
GROUP BY i.billingcountry
ORDER BY sales DESC;
See the PDF presenting the data: SQL project
Excel file with findings from SQL
The PowerPoint presenting the data: sql-project