Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for Funnel Segments

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

Your question is SQL for Funnel Segments. Start with the requirements and the two 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

Write a query to identify top-performing user segments based on multi-step conversion funnels.

Calculate performance for the funnel viewed_offer → started_application → completed_application. A user counts as started only when the start occurs after the view, and counts as completed only when completion occurs after the start. Include every segment, including segments with no qualifying starters.

Output

  1. One row per segment with segment, started_users, completed_users, conversion_rate, and performance_rank.
  2. conversion_rate is the completed-user percentage among qualifying starters, with zero for segments without starters.
  3. Sort by rank ascending, then segment alphabetically, with NULL segments last.

Schema

users
ColumnTypeDescription
user_idPKINTUnique user identifier
segmentVARCHAR(50)User segment label
funnel_events
ColumnTypeDescription
event_idPKINTUnique event identifier
user_idINTUser associated with the event
event_nameVARCHAR(40)Funnel event type
event_atTIMESTAMPTimestamp when the event occurred
Tablesusersfunnel_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results