Genre of each listener's first play
The task
The growth team wants to know which genre hooks new listeners. For every listener who has at least one play, find their first play: the one with the earliest played_at. If two plays have the same played_at, the one with the lower play_id is first.
The genre of a play is the genre of the artist of the track. Count how many listeners had their first play in each genre. Listeners with no plays are not counted, and a genre nobody started with does not appear.
Return genre and listeners. Sort by listeners descending, then genre ascending.
Expected output
genrelisteners- Sorted by listeners descending, then genre ascending.
- Checked on the sample and on 2 hidden datasets. How grading works
Tables Music streaming service · click a name to insert it
listeners180 rows in the sample
One row per listener account. Key: listener_id.
| int | Unique id. | |
| date | Day they joined. | |
| text | Two-letter country code. | |
| text | free, premium or family. |
artists30 rows in the sample
One row per artist. Key: artist_id.
| int | Unique id. | |
| text | Name. | |
| text | pop, rock, hip-hop, electronic, jazz or folk. |
tracks116 rows in the sample
One row per track. Key: track_id.
| int | Unique id. | |
| text | Track title. | |
| int | Main artist. | |
| int | Length. | |
| date | Release day. |
plays6,555 rows in the sample
One row per play. Key: play_id.
| bigint | Unique id. | |
| int | Who listened. | |
| int | What. | |
| timestamp | Start time (UTC). | |
| int | How long they listened. | |
| text | phone, desktop, speaker or car. |
Related questions
- Average first purchase value by campaign, organic includedmedium
- Each customer's largest single expense, with tie-breakersmedium
- Favourite spending category per customer, counted by segmenthard
- How far each artist climbed or fell from April to Mayhard
- Listener quartiles by May listening timemedium
- Repeat contact within 14 days of a first tickethard
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL