All problems

Where Do People Fall Off in Our Funnel?

hardSQLGroupBy

Kindled's growth team reports one number a week — the share of sign-ups that end in a purchase — and it has stopped being useful. Knowing that three people in eight bought something says nothing about the point at which the other five gave up. What they want instead is the width of the funnel at every stage, so the drop that matters is visible.

Nothing in this database describes a funnel. There is no table of stages and no column saying how far a person got. There is only a log: one row each time a person did something, with event_type naming what they did. The four stage names exist purely as values inside that column.

Two people can also log the same kind of event more than once — the log is a record of actions, not of milestones reached — so the report must count people, not lines in the log.

events — one row per action taken by a user. event_type is one of signup, view_product, add_to_cart or purchase. user_id is the person who took the action.

id user_id event_type event_date
1 1 signup 2023-05-01
2 1 view_product 2023-05-01
3 1 add_to_cart 2023-05-02
4 1 purchase 2023-05-03
5 2 signup 2023-05-02
6 2 view_product 2023-05-02
7 3 signup 2023-05-03
8 3 view_product 2023-05-03
9 3 add_to_cart 2023-05-04
10 4 signup 2023-05-04
11 4 view_product 2023-05-05
12 4 add_to_cart 2023-05-05
13 4 purchase 2023-05-06
14 5 signup 2023-05-05
15 6 signup 2023-05-06
16 6 view_product 2023-05-06
17 7 signup 2023-05-07
18 7 view_product 2023-05-07
19 7 add_to_cart 2023-05-08
20 7 purchase 2023-05-09
21 8 signup 2023-05-08

The table already exists in the database — there is nothing to create or load.

Task: Write a query returning two columns, event_type and num_users. num_users is how many different people logged at least one event of that kind; somebody who logged the same kind twice counts once. There is one row for every event type that appears in the log, and no row for a stage nobody ever reached. Rows come back in alphabetical order of event_type.

Example output — shape only; the figures below are invented, not this data's answer.

event_type num_users
add_to_cart 5
purchase 2
signup 12
view_product 9

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…