Plays that were immediately replayed
The task
The recommendations team wants to find tracks that listeners loved enough to play again straight away.
A play is an immediate replay candidate when the same listener's next play, by played_at, is of the same track. The next play is the listener's play with the earliest played_at after this one, whatever the date and whatever the track. If two plays of a listener share the same played_at, the lower play_id is first.
Consider only plays that started in June 2025 (from 2025-06-01 up to, but not including, 2025-07-01). Their next play may be on a later date, even in July.
Return the plays that are followed by a play of the same track:
play_idlistener_idtrack_idplayed_atreplayed_at: theplayed_atof the next play
Sort by played_at, then play_id.
Expected output
play_idlistener_idtrack_idplayed_atreplayed_at- Sorted by played_at ascending, then play_id 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
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL