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
Top Regions by Enrollment
00:00
5 left

Top Regions by Enrollment

MediumSQL · PostgreSQL

Problem

Aetna wants to identify the regional offices with the highest patient enrollment during the previous calendar month. Write a SQL query to return the top three regional offices based on distinct enrolled patients.

Output

  1. Return one row per regional office, with columns office_name and enrolled_patients.
  2. Count each patient at most once per office, and include only enrollment records from the previous calendar month relative to the fixed reporting date of September 15, 2026.
  3. Return the three offices with the highest counts, ordered by count descending and office_id ascending to break ties.
  4. Offices without qualifying enrollments may remain in the intermediate calculation but cannot appear in the top three when their count is lower.
  5. Enrollment records with a NULL patient_id are ignored by the distinct-patient count.

Schema

regional_offices
ColumnTypeDescription
office_idPKINTUnique regional office identifier
office_nameVARCHAR(100)Regional office name
region_codeVARCHAR(20)Short code identifying the region
patient_enrollments
ColumnTypeDescription
enrollment_idPKINTUnique enrollment record identifier
office_idINTRegional office associated with the enrollment
patient_idINTPatient identifier
enrollment_dateDATEDate the patient enrollment was recorded
Tablesregional_officespatient_enrollments
Interviewer

Your question is Top Regions by Enrollment. 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.