AnalystPath

Top-Streamed Track in Each Genre

SQLMediumMid level~15 min

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.

tracks
track_idtrack_namestreamsgenre_id
1Dawn Ride700001
2Neon Pulse900001
3Quiet Harbor800002
genres
genre_idgenre_name
1Electronic
2Ambient

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

Related SQL questions