Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Top Categories by Region

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

Your question is SQL Top Categories by Region. 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

Write a SQL query to find the top three selling product categories by region for the last fiscal quarter.

For this exercise, the last fiscal quarter is April 1, 2026 through June 30, 2026. Use units sold as the sales measure and exclude sales without a valid product category or region.

Output

  1. One row per qualifying region and category.
  2. Columns: region, category, units_sold, and category_rank.
  3. Include categories ranked from 1 through 3 within each region, including ties.
  4. Order by region, category_rank, then category.

Schema

sales
ColumnTypeDescription
sale_idPKINTUnique sales transaction identifier
product_idINTProduct sold in the transaction
store_idINTStore associated with the transaction
sale_dateDATEDate of the sale
quantityINTNumber of units sold
products
ColumnTypeDescription
product_idPKINTUnique product identifier
product_nameVARCHAR(100)Product name
categoryVARCHAR(60)Product category
stores
ColumnTypeDescription
store_idPKINTUnique store identifier
store_nameVARCHAR(100)Store name
regionVARCHAR(40)Geographic region assigned to the store
Tablessalesproductsstores
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results