Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Analyze Sell-Out With SQL
00:00
5 left

Analyze Sell-Out With SQL

MediumSQL · PostgreSQL

Problem

Write a SQL query to analyze sell-out by category, store, and week, and identify the top-performing locations for The Coca-Cola.

Use the provided product, store, and sell-out data. Exclude records with an unknown category or missing sale date. Return the top two location ranks within each category and week, including ties.

Output

  1. One row per included category, week, and top-ranked store
  2. Columns: category, week_start, store_name, total_units, location_rank
  3. Sort by category, week, rank, and store name

Schema

products
ColumnTypeDescription
product_idPKINTProduct identifier
product_nameVARCHAR(100)Product name
categoryVARCHAR(80)Product category
stores
ColumnTypeDescription
store_idPKINTStore identifier
store_nameVARCHAR(120)Coca-Cola location name
cityVARCHAR(80)Store city
regionVARCHAR(40)Geographic region
sell_out
ColumnTypeDescription
sell_out_idPKINTSell-out record identifier
product_idINTReferenced product
store_idINTReferenced store
sold_atDATESale date
unitsINTUnits sold
Tablesproductsstoressell_out
Interviewer

Your question is Analyze Sell-Out With 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.