Skip to content

Listeners who came back after a gap

The task

The retention team wants to find listeners who drift away and then return.

A listening day is a UTC calendar date on which a listener has at least one play (plays.played_at). A listener is reactivated on a listening day if the gap to their previous listening day is at least 14 calendar days. The gap is the difference between the two dates, so a play at 23:00 on 1 March followed by a play at 01:00 on 15 March is a 14 day gap. A listener's first listening day is never a reactivation.

Return one row per listener who was reactivated at least once: listener_id, reactivations (how many of their listening days were reactivations) and longest_gap_days (the largest gap among those reactivations). Sort by reactivations descending, then listener_id ascending.

Expected output

listener_idreactivationslongest_gap_days
  • Sorted by reactivations descending, then listener_id ascending.
  • Checked on the sample and on 3 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