Subscribers With Two Streams Within Five Days
Problem
A music app records each listening session. Table `streams` has `(stream_id, listener_id, played_on)` where `stream_id` is unique and `played_on` is a date.
Report the `listener_id` of every listener who has any two streams that occurred at most 5 days apart (the two dates differ by 5 days or fewer).
Return the result ordered by `listener_id` ascending.
Tables
Example rows — the live problem includes the full dataset.
streams
| stream_id | listener_id | played_on |
|---|---|---|
| 1 | 100 | 2024-01-01 |
| 2 | 100 | 2024-01-04 |
| 3 | 200 | 2024-01-01 |
Expected output
Your answer should return 2 rows with the columns listener_id.
Starter code (SQL)
SELECT *
FROM streams;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock