Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 feedbackSuccess 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
Window Functions for Enrollment Growth
00:00
5 left

Window Functions for Enrollment Growth

MediumSQL · PostgreSQL

Problem

Write a SQL query using window functions to calculate month-over-month changes in household enrollment and rank regions by growth within each country.

Use the provided enrollment and region tables. Include only region-month rows with a prior observed month for comparison.

Output

  1. One row per country, region, and month with a prior month
  2. Columns: country, region_name, enrollment_month, household_enrollment, mom_change, mom_growth_pct, and growth_rank
  3. Rank regions within each country and month by percentage growth descending, with ties sharing a rank
  4. Order by country, enrollment_month, growth_rank, and region_name

Schema

regions
ColumnTypeDescription
region_idPKINTUnique region identifier
countryVARCHAR(100)Country containing the region
region_nameVARCHAR(100)Region name
household_enrollments
ColumnTypeDescription
enrollment_idPKINTUnique enrollment record identifier
household_idVARCHAR(50)Household identifier
region_idINTRegion associated with the enrollment
enrollment_dateDATEDate of enrollment
Tablesregionshousehold_enrollments
Interviewer

Your question is Window Functions for Enrollment Growth. Start with the requirements and the two 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.