Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL for Weekly Inventory Turnover
00:00
5 left

SQL for Weekly Inventory Turnover

MediumSQL · PostgreSQL

Problem

Write a SQL query to calculate weekly inventory turnover by store at Walmart and rank stores by turnover within each region.

Use the provided store, inventory snapshot, and sales transaction data for the week beginning January 6, 2025. Include active stores with inventory records for the week, including stores with no qualifying sales.

Output

  1. One row per active store and week
  2. Columns: week_start, region, store_id, store_name, cogs, avg_inventory_value, turnover, and regional_rank
  3. Turnover is cost of goods sold divided by average inventory value
  4. Sort by region, regional_rank, then store_id

Schema

stores
ColumnTypeDescription
store_idPKINTUnique Walmart store identifier
store_nameVARCHAR(100)Store display name
regionVARCHAR(50)Operational region containing the store
is_activeBOOLEANWhether the store is currently active
inventory_snapshots
ColumnTypeDescription
snapshot_idPKINTUnique inventory snapshot identifier
store_idINTStore associated with the snapshot
snapshot_dateDATEDate of the inventory measurement
inventory_valueNUMERIC(14,2)Inventory value at the snapshot date
sales_transactions
ColumnTypeDescription
transaction_idPKINTUnique sales transaction identifier
store_idINTStore where the sale occurred
sale_dateDATEDate of the sale
quantityINTUnits sold
unit_costNUMERIC(10,2)Cost per unit sold
Tablesstoresinventory_snapshotssales_transactions
Interviewer

Your question is SQL for Weekly Inventory Turnover. 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.