I need to write a query to show the number of tracks sold per artist per year for the top 10 best selling artists. Take the overall top 10 for all years.
This is what I have:
SELECT TOP 10 a.Name, YEAR(i.InvoiceDate), count(t.TrackId)
FROM Artist a
INNER JOIN Album al on a.ArtistId = al.ArtistId
INNER JOIN Track t on al.AlbumId = t.AlbumId
INNER JOIN InvoiceLine il on t.TrackId = il.TrackId
INNER JOIN invoice i on il.InvoiceId = i.InvoiceId
Group by YEAR(i.InvoiceDate), a.Name
ORDER by count(t.TrackId) DESC;
I don't only the top 10 of all the tracks sold by on group and not by each year the top 10.

Asked by joachim soetinck
(1 rep)
Feb 11, 2019, 08:17 PM
Last activity: Feb 11, 2019, 11:38 PM
Last activity: Feb 11, 2019, 11:38 PM