Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top 3 Products Per Region

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

Your question is Top 3 Products Per Region. Start with the requirements and the four 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

Abbott's commercial analytics team needs a regional view of its best-selling medical device products. Write a PostgreSQL query for the last completed quarter, defined here as 2025-04-01 through 2025-06-30.

Requirements

  1. Include only orders with status = 'Completed' during the specified quarter.
  2. Join regions, orders, order items, and products to calculate total units sold by region and product.
  3. Return the top three products within each region, ranking by total units sold descending and resolving ties by product_name ascending.
  4. Exclude products with non-positive or NULL quantities and return regions with qualifying sales only.

Schema

regions
ColumnTypeDescription
region_idPKINTEGERUnique Abbott sales region identifier
region_nameVARCHAR(100)Sales region name
sales_orders
ColumnTypeDescription
order_idPKINTEGERUnique sales order identifier
region_idINTEGERRegion assigned to the order
order_dateDATEDate the order was placed
statusVARCHAR(20)Order processing status
sales_order_items
ColumnTypeDescription
order_idPKINTEGERRelated sales order identifier
product_idPKINTEGERRelated medical device product identifier
quantityINTEGERNumber of units sold
products
ColumnTypeDescription
product_idPKINTEGERUnique product identifier
product_nameVARCHAR(150)Abbott medical device product name
Tablesregionssales_orderssales_order_itemsproducts
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results