Accounts Streaming From Two Devices at Once
Problem
Table: `stream_session`
| Column Name | Type |
|---|---|
| profile_id | int |
| device_id | int |
| started_at | datetime |
| ended_at | datetime |
There is no primary key. Each row is one viewing session: a profile streamed from a device between `started_at` and `ended_at`.
A profile is flagged for sharing when it had **two sessions on different devices that overlapped in time** (one session started while another, on a different device, was still running). Return the distinct `profile_id` of every such profile.
Tables
Example rows — the live problem includes the full dataset.
| profile_id | device_id | started_at | ended_at |
|---|---|---|---|
| 1 | 100 | 2026-01-01 10:00:00 | 2026-01-01 11:00:00 |
| 1 | 200 | 2026-01-01 10:30:00 | 2026-01-01 12:00:00 |
| 2 | 300 | 2026-01-01 08:00:00 | 2026-01-01 09:00:00 |
Expected output
Your answer should return 1 row with the columns profile_id.
Starter code (SQL)
SELECT *
FROM stream_session;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