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.
| 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
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL