Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Funnel Drop-Off Detection

HardSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL Funnel Drop-Off Detection. Start with the requirements and the three tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Apple Store analytics receives user funnel events from a distributed warehouse. Write a PostgreSQL query that identifies consecutive missing steps in each user session's purchase funnel.

Use the canonical Apple Store funnel defined in funnel_steps. Report only missing-step streaks containing at least two consecutive steps.

Requirements

  1. Deduplicate repeated events for the same user, session, and funnel step.
  2. Include every canonical funnel step for each observed session, marking whether the step was reached.
  3. Use window functions to assign consecutive missing steps to the same streak.
  4. Return the user, session, last reached step before the streak, streak boundaries, and streak length.
  5. Exclude completed sessions and isolated one-step gaps, and order results by user and starting step.

Schema

apple_store_users
ColumnTypeDescription
user_idPKINTApple Store user identifier
countryVARCHAR(30)User billing country
signup_dateDATEDate the user registered
funnel_events
ColumnTypeDescription
event_idPKINTUnique event identifier
user_idINTReferences apple_store_users.user_id
session_idVARCHAR(20)Apple Store browsing session
event_tsTIMESTAMPTimestamp when the event occurred
device_typeVARCHAR(20)Client device category
funnel_steps
ColumnTypeDescription
step_numberPKINTCanonical order of the funnel step
step_nameVARCHAR(30)Canonical Apple Store funnel step name
Tablesapple_store_usersfunnel_eventsfunnel_steps
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results