Checkout Funnel

MediumSQLSQL

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

Table events: user_id INTEGER step TEXT 'view', 'cart' or 'purchase' at TEXT 'YYYY-MM-DD HH:MM' A user can fire the same step many times, and nothing forces the steps to arrive in order. Return one row with how many distinct users reached each stage, where reaching a stage means having fired that step and every step before it: viewed — fired 'view' carted — fired 'view' and 'cart' purchased — fired 'view', 'cart' and 'purchase' Columns, in this order: viewed, carted, purchased. The result is always exactly one row.

Examples

Input: events user_id | step | at 1 | view | 2026-06-01 10:00 1 | cart | 2026-06-01 10:02 2 | view | 2026-06-01 11:00 3 | purchase | 2026-06-01 12:00
Output: 2 | 1 | 0
User 3 purchased without a view or a cart on record, so they are in no stage.

Constraints

  • Timestamps do not matter for this question, only which steps a user has.
  • An empty table gives 0 | 0 | 0.

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More SQL problems