D8LooPFocus modeCODE WORKSPACE
Return users whose first checkout happened after their first view.
Start by naming the output grain, then build CTEs that can be inspected one at a time.
Sample input
| user_id | event_name | event_time |
|---|---|---|
| 1 | view | 2026-01-01 03:30:00 |
| 1 | checkout | 2026-01-01 04:10:00 |
| 2 | view | 2026-01-01 22:15:00 |
| 2 | checkout | 2026-01-02 00:30:00 |
Expected output
| user_id | first_view_at | first_checkout_at |
|---|---|---|
| 1 | 2026-01-01 03:30:00 | 2026-01-01 04:10:00 |
| 2 | 2026-01-01 22:15:00 | 2026-01-02 00:30:00 |
Constraints
State the output contract first, use readable CTE layers, return the exact columns requested by the prompt, and use deterministic ordering.
Expected skills
Interview clarification, SQL structure, edge-case handling, and final-answer narration.
Run the SQL query to inspect preview rows.