← Problems56. Funnel drop-off by stepMediumSQL
00:00 / 30:00

Funnel drop-off by step

MediumNot attempted yetAsked at Adobe

A web analytics report measures how many visitors survive each step of a signup funnel. The funnel is strict: a visitor counts at step k only if they have an event for step k and for every step before it. Reaching step 3 without step 2 counts for step 1 only.

Input schema

funnel_steps step_index int -- 1..N, contiguous, one row per step step_name string events event_id bigint visitor_id string step_name string -- always one of funnel_steps.step_name occurred_at timestamp

Constraints

  • Return step_index, step_name, visitors, drop_off_pct, ordered by step_index
  • visitors counts distinct visitors who reached that step and every earlier one
  • drop_off_pct is the percentage lost from the previous step, round(..., 2)
  • drop_off_pct is null for step 1, and null when the previous step had 0 visitors
  • A step nobody reached still appears, with 0 visitors
  • Repeat events for the same visitor and step count once
  • Up to 20,000,000 events

Example 1half the visitors survive each step

Input · events
event_idstep_namevisitor_idoccurred_at
1viewv12026-05-01 09:00:00
2signupv12026-05-01 09:05:00
3activatev12026-05-01 09:10:00
4viewv22026-05-01 10:00:00
5signupv22026-05-01 10:05:00
6viewv32026-05-01 11:00:00
1 more row in this case
Input · funnel_steps
step_namestep_index
view1
signup2
activate3
Output
step_indexstep_namevisitorsdrop_off_pct
1view4null
2signup250
3activate150

Example 2skipping a step forfeits everything after it

Input · events
event_idstep_namevisitor_idoccurred_at
1viewv12026-05-02 09:00:00
2activatev12026-05-02 09:10:00
3viewv22026-05-02 10:00:00
4signupv22026-05-02 10:05:00
Input · funnel_steps
step_namestep_index
view1
signup2
activate3
Output
step_indexstep_namevisitorsdrop_off_pct
1view2null
2signup150
3activate0100

Topics

window functionsfunnel analysisaggregation

Similar problems

Community-reported interview topic. Not an official company question and no affiliation is implied.

solution.sql
Loading editor…
Draft not saved yet · Spaces 4 · UTF-8⌘↵ run ⌘⇧↵ submit
Nothing run yet

Run against the public tests, or submit to score against all of them.