Gaps between plays
Gaps between plays
You are a product analyst at the music streaming service TuneWave. The recommendations team wants to know how densely listeners consume tracks: short pauses mean continuous playlist listening, long ones mean the person re-opened the app. You have the track-start log play_events: who pressed Play and when.
For every event, compute how many minutes passed since the previous event of the same user. Skip the very first event of each user — there is nothing to compare it with.
Return columns:
- user_id — listener identifier;
- played_at — track start time (timestamp, as stored);
- minutes_since_prev — whole number of minutes since the user's previous event (all gaps in the data are exact minutes).
Sort by user_id ascending, then played_at ascending. Users with a single event do not appear in the output. Timestamps never repeat within one user.
Expected output sample
This is what a correct answer looks like — its row count is its own, it doesn't have to match the schema tables. Your answer must use the same column names as this sample — alias them with AS if needed.
| user_id | played_at | minutes_since_prev |
|---|---|---|
| 1 | 2026-05-01T09:03:00 | 3 |
| 1 | 2026-05-01T09:10:00 | 7 |
| 1 | 2026-05-01T10:00:00 | 50 |
Sign in to see submission history
Sign inSign in to use AI Mentor
Sign in