The executive team wants to understand revenue distribution across music genres. For each genre, calculate the total revenue, its percentage share of total revenue, and its rank.
Use window functions to compute the percentage and rank without subqueries.
| Column | Type |
|---|---|
| GenreId | INTEGER (Primary Key) |
| Name | TEXT |
| Column | Type |
|---|---|
| InvoiceLineId | INTEGER (Primary Key) |
| InvoiceId | INTEGER (Foreign Key) |
| TrackId | INTEGER (Foreign Key) |
| UnitPrice | NUMERIC(10,2) |
| Quantity | INTEGER |
GenreRevenue = SUM(UnitPrice * Quantity), rounded to 2RevenuePercent using a window SUM over the total, rounded to 2RevenueRank using RANK() ordered by revenue descendingReady to take your skills to the next level? Enroll in our comprehensive Data Analyst Career Track to master SQL, Python, Excel, and Power BI.
Run your code to see the result here.