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
Upgrade Twice in Year
00:00
5 left

Upgrade Twice in Year

MediumSQL · PostgreSQL

Problem

Given a dataset of customer subscriptions, how would you write a query to identify customers who upgraded their plans twice within the same calendar year?

Use the provided subscription history, customer, and plan data. Treat a change to a plan with a higher plan level as an upgrade, and identify customers with at least two upgrades in one calendar year.

Output

  1. One row per qualifying customer and calendar year
  2. Columns: customer_id, customer_name, upgrade_year, upgrade_count, first_upgrade_date, and last_upgrade_date
  3. Include only customer-years with at least two upgrades
  4. Order by customer_id, then upgrade_year ascending

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(120)Customer display name
plans
ColumnTypeDescription
plan_idPKINTUnique plan identifier
plan_nameVARCHAR(80)Chargebee subscription plan name
plan_levelINTOrdinal value used to compare plan tiers
subscription_history
ColumnTypeDescription
subscription_idPKINTUnique subscription history record
customer_idINTCustomer associated with the plan record
plan_idINTPlan active from the effective timestamp
effective_atTIMESTAMPTimestamp when the plan became effective
Tablescustomersplanssubscription_history
Interviewer

Your question is Upgrade Twice in Year. 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.