Skip to content

Genre of each listener's first play

MediumFreeRanking and top NJoins12 min2 hidden datasets

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.

intUnique id.
dateDay they joined.
textTwo-letter country code.
textfree, premium or family.
artists30 rows in the sample

One row per artist. Key: artist_id.

intUnique id.
textName.
textpop, rock, hip-hop, electronic, jazz or folk.
tracks116 rows in the sample

One row per track. Key: track_id.

intUnique id.
textTrack title.
intMain artist.
intLength.
dateRelease day.
plays6,555 rows in the sample

One row per play. Key: play_id.

bigintUnique id.
intWho listened.
intWhat.
timestampStart time (UTC).
intHow long they listened.
textphone, desktop, speaker or car.

Related questions

Loading the editor and PostgreSQL