Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Regions Month Over Month

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Top Regions Month Over Month. Start with the requirements and the two tables on the right.

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.

Problem

Siemens Healthineers wants to monitor monthly commercial performance across regions. Write a PostgreSQL query that compares medical equipment sales with monthly regional targets and identifies the three strongest regions for each month.

Requirements

  1. Aggregate sales by region and calendar month.
  2. Join the aggregated sales with matching regional targets.
  3. Calculate target attainment as sales divided by target, expressed as a percentage.
  4. Rank regions within each month and return only the top three, using region code as the tie-breaker.

Schema

equipment_sales
ColumnTypeDescription
sale_idPKINTUnique medical equipment sale identifier
region_codeVARCHAR(20)Region responsible for the sale
sale_dateDATEDate on which the sale was recorded
equipment_modelVARCHAR(100)Siemens Healthineers equipment model sold
sale_amountNUMERIC(12,2)Value of the equipment sale
regional_targets
ColumnTypeDescription
target_idPKINTUnique monthly target identifier
region_codeVARCHAR(20)Region to which the target applies
target_monthDATEFirst day of the target month
target_amountNUMERIC(12,2)Monthly sales target for the region
Tablesequipment_salesregional_targets
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results