Drivers can be logged in from two devices, so their online sessions overlap, nest inside each other, or touch (one ends exactly when the next begins). Merge overlapping or touching sessions per driver into continuous blocks. Return driver_id, merged_sessions (number of blocks) and online_minutes (total minutes covered by the blocks, as an integer). Order by driver_id.
| Column | Type |
|---|---|
| driver_id | INTEGER |
| login_at | TIMESTAMP |
| logout_at | TIMESTAMP |
| driver_id | login_at | logout_at |
|---|---|---|
| 1 | 2026-05-01 08:00:00 | 2026-05-01 10:00:00 |
| 1 | 2026-05-01 09:30:00 | 2026-05-01 11:00:00 |
| 1 | 2026-05-01 13:00:00 | 2026-05-01 14:00:00 |
| 2 | 2026-05-01 07:00:00 | 2026-05-01 12:00:00 |
| 2 | 2026-05-01 08:00:00 | 2026-05-01 09:00:00 |
| 3 | 2026-05-01 18:00:00 | 2026-05-01 19:30:00 |
| driver_id | merged_sessions | online_minutes |
|---|---|---|
| 1 | 2 | 240 |
| 2 | 1 | 300 |
| 3 | 1 | 90 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Longest Daily Login Streak · Median Delivery Time per Dark Store ›
{{ totalCount }} questions in the style asked at Amazon, Microsoft, Google, Meta, Flipkart and more — {{ hardPct }}% Hard. Write SQL in a real database engine in your browser, run it on sample data, then evaluate against hidden tests.
Company tags show where this type of question is commonly reported in interviews. Questions, data and solutions are written by TechTown.
{{ cur.statement }}
No submissions yet. Press Evaluate to submit your query.
{{ solutionSql }}
{{ out.error }}
You have solved your 3 free questions — nice work! Log in (free) to unlock all 150 questions, keep your streak and appear on the leaderboard.