Group events into sessions: «gap > 30 min starts a new one»
Web analytics splits a user's event stream into sessions by the rule: «a new session starts when the gap to the previous event for that user exceeds 30 minutes». For every user count the number of such sessions. Hint: look at the difference between the current and previous timestamp within the user; mark «session start» where the gap exceeds 30 minutes or there's no previous timestamp at all (this is the first event). The sum of those marks per user is the session count. Sort by user id.
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.
| user_id | sessions |
|---|---|
| 1 | 2 |
| 2 | 1 |
| 3 | 1 |
Sign in to see submission history
Sign inSign in to use AI Mentor
Sign in