Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
SQL for Churn Cohorts
00:00
5 left

SQL for Churn Cohorts

HardSQL · PostgreSQL

Problem

Write a SQL query to analyze customer churn by cohort and identify the top drivers of churn.

Use customer sign-up cohorts through June 2024 and consider churn events from the sign-up date through September 30, 2024. For each churn driver, include the number of affected customers and their average completed orders before churn.

Output

  1. One row per cohort and churn driver, limited to the top three drivers within each cohort.
  2. Columns: cohort_month, churn_driver, churned_customers, cohort_customers, churn_rate_pct, avg_pre_churn_orders, and driver_rank.
  3. Sort by cohort_month ascending and driver_rank ascending, with churn count, average orders, and driver name resolving ties.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
signup_dateDATECustomer signup date
churn_events
ColumnTypeDescription
churn_event_idPKINTUnique churn event identifier
customer_idINTCustomer associated with the churn event
churn_dateDATEDate the customer churned
churn_reasonVARCHAR(100)Reported primary churn driver
orders
ColumnTypeDescription
order_idPKINTUnique order identifier
customer_idINTCustomer who placed the order
order_dateDATEDate the order was placed
order_amountNUMERIC(10,2)Order subtotal
Tablescustomerschurn_eventsorders
Interviewer

Your question is SQL for Churn Cohorts. Start with the requirements and the three tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.