How would you build a funnel analysis in SQL, measuring how many users progress through a sequence of steps?

Last updated 13 July 2026

  • Pivot events to one row per user with each step's earliest timestamp, e.g. MIN(CASE WHEN event='cart' THEN ts END) (conditional aggregation).

  • Count a user at a step only if every prior step exists with increasing timestamps. Otherwise unordered events overstate conversion.

  • Count survivors per step, then divide adjacent steps (step conversion) or by step 1 (overall). Optionally require steps within an attribution window.

  • https://medium.com/@mohitdaxini75
  • https://blog.devgenius.io/pattern-012-funnel-analysis-in-sql-how-many-users-actually-made-it-to-the-end-b9b3d144f670
  • https://dev.to/michaelnocito/funnel-conversion-in-sql-and-the-step-that-shows-100-3g0f
All Advanced SQL interview questions