Top-Streamed Track in Each Genre
Problem
A music service stores monthly stream counts per track, and each track belongs to a genre.
Table: `tracks`
| Column | Type |
|-------------|---------|
| track_id | int |
| track_name | varchar |
| streams | int |
| genre_id | int |
`track_id` is the primary key; `genre_id` references `genres.genre_id`.
Table: `genres`
| Column | Type |
|-------------|---------|
| genre_id | int |
| genre_name | varchar |
`genre_id` is the primary key.
Write a query that returns, for each genre, the track(s) with the **highest** stream count in that genre. If several tracks tie for the most streams in a genre, return all of them.
Return three columns named `genre`, `track`, and `streams`, in any order.
Tables
Example rows — the live problem includes the full dataset.
| track_id | track_name | streams | genre_id |
|---|---|---|---|
| 1 | Dawn Ride | 70000 | 1 |
| 2 | Neon Pulse | 90000 | 1 |
| 3 | Quiet Harbor | 80000 | 2 |
| genre_id | genre_name |
|---|---|
| 1 | Electronic |
| 2 | Ambient |
Expected output
Your answer should return 3 rows with the columns genre, track, streams.
Starter code (SQL)
SELECT *
FROM tracks;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock