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 Three Selling Products SQL
00:00
5 left

Top Three Selling Products SQL

MediumSQL · PostgreSQL

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
Interviewer

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