SQL for BAs: funnels, cohorts and retention
Count users at each funnel step and the share each cohort keeps, in SQL, and check the counts so that no user is counted twice.
L1–L4 are part of the Pro pass
L0 Explain simply
Analogy: a turnstile at each gate. A fairground counts people at the rides, at the food stall and at the show. A good count counts each person once at each gate, even if they walk through the food gate three times.
Daily List is a made-up to-do app (SYNTHETIC / TRAINING ONLY). Nina wants the numbers behind the funnel. Sam, the , writes the queries. An earlier lesson showed how to read the grid. This one builds the numbers.
What it is: (Structured Query Language) can count people across steps. A table is a grid, a row is one event, and a column is one fact. A drop-off is the people lost between one step and the next. A is the share of a cohort still active after a stated time. A cohort table is a grid with one row per cohort and one column per period. Each cell is a count of people. Counting rows is the neighbour of counting people. One person can make many rows.
Why it matters: User 2 shared a list twice. A count of rows says 3 shares. A count of people says 2. User 5 upgraded on sign-up day and never added a task. An unordered funnel still counts that upgrade. An ordered funnel does not.
The number shows where people leave. It does not show why.
PLAIN WORDS · 3 in this section
- turnstile
- a gate with a turning bar for one person
- fairground
- A place with rides and games.
- unordered
- with no first, last or next item
PICTURE IT
The picture is the one the lesson above opens with. The table below shows how each part of it matches the work.
THE REAL JOB The picture helps a newcomer remember to count people once at each gate, and to check that the first count matches the crowd.
- Define the steps
- Count distinct users
- Order and time-limit
- Build the cohort grid
- Check month zero
HOW THE PICTURE MAPS
| In the picture | In the work |
|---|---|
| A turnstile at each gate | A step count |
| Counting a person once, however often they pass | Counting distinct users |
| Visitors who must pass gate one before gate two | An ordered funnel |
| The register of who entered in each month | A cohort grid |
| A crowd bigger than the number who bought tickets | A rate above one hundred percent |
WHERE THIS PICTURE STOPS
- A turnstile cannot tell if the same person passed twice. A query needs a user number for that.
- Gates are in one place. Events come from many systems and can arrive late.
- A fair has an opening day. A cohort has a start date for each user.
HOOK
Count people, not passes.
REMEMBER IT THIS WAY
A sequence: the real steps, in order.
Ask: which gate, how many different people, out of which cohort?
| In the trick | What it stands for |
|---|---|
| gate | A turnstile at each one counts people |
| cohort | share of a cohort that is still active |
TELL A FRIEND
A funnel counts unique users under an agreed entry/order/window rule. A cohort divides qualifying active users by an independently known cohort size; month zero is the full cohort only when the definition guarantees that activity; observed zero differs from an interval not yet observed.
OFTEN MIXED UP WITH Funnels, cohorts and product analytics. That topic teaches how to read funnels and cohort tables. This one builds the numbers in Structured Query Language ().
PRACTISE AND KEEP
Sources for this topic — 5 sources
- Market practice
Understanding funnel analysis (Amplitude) ↗ — Amplitude · Live publisher How Amplitude computes funnels opened6November 2026: Any order, This order, Exact order and repeated events. Educational SQL does not claim to reproduce proprietary internals.
Live publisher How Amplitude computes funnels opened6November2026: Any order, This order, Exact order and repeated events. Educational SQL does not claim to reproduce proprietary internals.
- Market practice
Retention report (Mixpanel documentation) ↗ — Mixpanel · Live publisher Retention documentation opened6November 2026: starting/return events and incomplete observation intervals. The local SQL cohort is a simplified educational implementation, not a claim to duplicate Mixpanel internals.
Live publisher Retention documentation opened6November2026: starting/return events and incomplete observation intervals. The local SQL cohort is a simplified educational implementation, not a claim to duplicate Mixpanel internals.
- Market practice
WITH Queries (Common Table Expressions) (PostgreSQL documentation) ↗ — PostgreSQL Global Development Group · PostgreSQL 18, §7.8 WITH, materialization, recursion and cycle detection; publisher page opened6November 2026. Dialect scope explicit.
PostgreSQL18 publisher documentation opened on6November2026: §7.8 WITH, materialization, recursion and cycle detection. No execution on PostgreSQL is claimed; engine-specific examples remain scoped to18.
- Market practice
SQLite: date/time functions ↗ — SQLite project · SQLite: date/time functions; ISO text/julianday/date modifiers, numeric subtraction contrast. Publisher page opened6November 2026.
Publisher documentation opened on6November2026. Engine/version scope is explicit; other database implementations may differ. Teaching queries are synthetic, not a required publisher template.
- Simplified educational illustration
Payments Signal editorial teaching models — Payments Signal
What this simplifies: Daily List people, data and exercises are invented for teaching. Query results belong to the declared fixture and database version. Authorization, business identity, time bounds and unknown-value policy must be agreed in context; no universal mandatory query template is implied.
Used wherever diagrams, scenarios, figures, or example values are didactic constructions rather than sourced facts; every such use carries a simplifications disclosure. All people, companies, banks, and list entries in examples are fictional.
Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.