Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Three Performing Sales Regions

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

Your question is Top Three Performing Sales Regions. 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

Business Context

Merck's commercial analytics team is reviewing 2025 net sales for Keytruda across active sales regions. The dashboard should identify the strongest regions using completed transactions only.

Task

Write a PostgreSQL query that returns the top three active sales regions by total Keytruda net sales during calendar year 2025.

Requirements

  1. Join the region and sales tables, retaining active regions even when they have no qualifying transactions.
  2. Include only completed Keytruda transactions dated from 2025-01-01 through 2025-12-31.
  3. Aggregate net sales by region, treat missing sales totals as zero, rank regions from highest to lowest revenue, and return the top three.
  4. Use a deterministic secondary sort by region name when totals are tied.

Schema

sales_regions
ColumnTypeDescription
region_idPKINTEGERUnique sales region identifier
region_nameVARCHAR(100)Display name of the sales region
is_activeBOOLEANIndicates whether the region is active
regional_sales
ColumnTypeDescription
sale_idPKINTEGERUnique sales transaction identifier
region_idINTEGERSales region associated with the transaction
product_nameVARCHAR(100)Merck product sold
sale_dateDATEDate when the sale was recorded
statusVARCHAR(30)Transaction processing status
net_sales_usdNUMERIC(14,2)Net sales amount in US dollars
Tablessales_regionsregional_sales
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results