Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Three Selling Products SQL

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

Your question is Top Three Selling Products SQL. Start with the requirements and the three 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

DICK'S Sporting Goods wants a regional sales view to identify the best-selling products across its store regions. Product rankings should be based on completed sales during calendar year 2025.

Task

Write a PostgreSQL query that returns the top three products by total units sold for each region.

Requirements

  1. Join the regional, product, and sales data.
  2. Include only sales with sale_status = 'completed' and sale dates in 2025.
  3. Aggregate units sold by region and product, then rank products within each region using a window function.
  4. Return the region name, product name, total units sold, and rank. Break ties alphabetically by product name and sort the final output by region and rank.

Schema

regions
ColumnTypeDescription
region_idPKINTUnique regional identifier
region_nameVARCHAR(50)DICK'S Sporting Goods sales region name
products
ColumnTypeDescription
product_idPKINTUnique product identifier
product_nameVARCHAR(100)Product display name
sales
ColumnTypeDescription
sale_idPKINTUnique sale record identifier
region_idINTRegion associated with the sale
product_idINTProduct associated with the sale
units_soldINTNumber of units sold
sale_statusVARCHAR(20)Transaction status
sale_dateDATETransaction date
Tablesregionsproductssales
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results