Session Identification via Gap Detection
Problem
**[Classic — streaming and analytics companies]**
A new session begins when the gap between consecutive events from the same user
exceeds **30 minutes**.
Return `user_id`, `session_num`, and `event_count`, ordered by user then session.
Tables
Example rows — the live problem includes the full dataset.
page_events
| event_id | user_id | event_time |
|---|
Expected output
Your answer should return 4 rows with the columns user_id, session_num, event_count.
Starter code (SQL)
SELECT *
FROM page_events;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