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 Rolling Churn With Seasonality
00:00
5 left

SQL Rolling Churn With Seasonality

HardSQL · PostgreSQL

Problem

Write a SQL query to identify customer churn patterns over a rolling three-month window, accounting for seasonal variations.

Use the provided customer, monthly activity, and seasonal factor data. Evaluate the latest available month, treating missing activity as inactivity and preserving customers with no activity.

Output

  1. One row per customer for the latest available month.
  2. Columns: customer_id, customer_name, window_end, rolling_active_months, rolling_spend, seasonal_expected_active_months, seasonally_adjusted_activity_ratio, and churn_pattern.
  3. Classify customers as churned, at_risk, or retained; sort by customer_id ascending.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer display name
signup_dateDATEDate the customer joined
regionVARCHAR(50)Customer geographic region
monthly_customer_activity
ColumnTypeDescription
activity_idPKINTUnique monthly activity record
customer_idINTReferenced customer
activity_monthDATEFirst day of the activity month
is_activeBOOLEANWhether the customer was active that month
monthly_spendNUMERIC(12,2)Customer spend during the month
seasonal_factors
ColumnTypeDescription
month_numberPKINTCalendar month number from 1 through 12
month_nameVARCHAR(20)Calendar month name
expected_active_rateNUMERIC(5,2)Expected fraction of customers active in the month
Tablescustomersmonthly_customer_activityseasonal_factors
Interviewer

Your question is SQL Rolling Churn With Seasonality. 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.