Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Common Pre-Churn User Paths

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

Your question is Common Pre-Churn User Paths. 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

Given a table of user events, how do you identify the most common path a user takes before churning at Superhuman?

Use the provided user and event data. Treat a user's path as all non-null events occurring before that user's churn timestamp, ordered chronologically.

Output

  1. Return one row for the most common path, with ties resolved alphabetically.
  2. Include path and churned_users, representing the event sequence and number of churned users following it.
  3. Sort by churned_users descending, then path ascending.

Schema

users
ColumnTypeDescription
user_idPKINTUnique Superhuman user identifier
emailVARCHAR(255)User email address
churned_atTIMESTAMPTimestamp when the user churned, or NULL for active users
user_events
ColumnTypeDescription
event_idPKINTUnique event identifier
user_idINTUser associated with the event
event_nameVARCHAR(100)Name of the event recorded in Superhuman
event_timestampTIMESTAMPTime when the event occurred
Tablesusersuser_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results