Sessions
events logs what users did: minute is the time of an event, in minutes from the start of the log. A user's events fall into sessions: an event starts a new session when it comes more than 30 minutes after that user's previous event, and a user's first event always starts one. Return each user_id with sessions, the number of sessions that user had. Rows may come in any order.
Example 1
events
| user_id | minute |
|---|---|
| 1 | 0 |
| 1 | 10 |
| 1 | 40 |
| 1 | 71 |
| 2 | 5 |
| 2 | 300 |
returns
| user_id | sessions |
|---|---|
| 1 | 2 |
| 2 | 2 |
Constraints
- Up to 18 events
Write it in your browser, against the clock. The model query, with a note on each piece of it, comes after.
More SQL problems
- Three Days RunningHard
- Top Two Salaries per DepartmentHard
- Worst DrawdownHard
- Between Two PricesBeginner
- Both ConditionsBeginner
- Cheapest FirstBeginner
- Each Symbol OnceBeginner
- How Many SellsBeginner