Split each user's events into sessions: a new session starts at the user's first event and whenever more than 30 minutes (1800 seconds) passed since that user's previous event (exactly 30 minutes stays in the same session). A cart session has at least one 'add_to_cart'; a converted session has both 'add_to_cart' and 'checkout' in the SAME session. Return one row: total_sessions, cart_sessions, converted_sessions and conversion_pct = 100 * converted / cart sessions, ROUND to 1.
| Column | Type |
|---|---|
| user_id | INTEGER |
| event_ts | TIMESTAMP |
| event_name | TEXT |
| user_id | event_ts | event_name |
|---|---|---|
| 1 | 2026-07-01 10:00:00 | open |
| 1 | 2026-07-01 10:05:00 | view |
| 1 | 2026-07-01 10:10:00 | add_to_cart |
| 1 | 2026-07-01 10:20:00 | checkout |
| 1 | 2026-07-01 11:30:00 | open |
| 1 | 2026-07-01 11:35:00 | add_to_cart |
| 2 | 2026-07-01 09:00:00 | open |
| 2 | 2026-07-01 09:20:00 | view |
| total_sessions | cart_sessions | converted_sessions | conversion_pct |
|---|---|---|---|
| 4 | 3 | 2 | 66.7 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
{{ 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.