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 Plan Upgrade Detection
00:00
5 left

SQL Plan Upgrade Detection

MediumSQL · PostgreSQL

Problem

Given a relational schema representing user subscriptions, write a SQL query to identify customers who upgraded their plans twice within a single month.

Use the customers, subscription_changes, and plans tables. An upgrade occurs when the new plan has a higher rank than the previous plan. Include customers with at least two upgrades in the same calendar month.

Output

  1. One row per qualifying customer and calendar month
  2. Columns: customer_id, customer_name, upgrade_month, and upgrade_count
  3. Sort by upgrade_month ascending, then customer_id ascending

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer display name
regionVARCHAR(50)Customer billing region
subscription_changes
ColumnTypeDescription
change_idPKINTUnique subscription change identifier
customer_idINTCustomer affected by the change
old_plan_idINTPlan before the change, null for an initial subscription
new_plan_idINTPlan after the change
changed_atTIMESTAMPTimestamp when the plan change occurred
plans
ColumnTypeDescription
plan_idPKINTUnique plan identifier
plan_nameVARCHAR(50)Plan display name
plan_rankINTOrdinal level used to compare plan tiers
monthly_priceDECIMAL(10,2)Monthly list price
Tablescustomerssubscription_changesplans
Interviewer

Your question is SQL Plan Upgrade Detection. 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.