AnalystPath

Subscribers With Two Streams Within Five Days

SQLMediumMid level~15 min

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_idlistener_idplayed_on
11002024-01-01
21002024-01-04
32002024-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

Related SQL questions