Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Store KPI SQL Analysis
00:00
5 left

Store KPI SQL Analysis

MediumSQL · PostgreSQL

Problem

Write a SQL query to analyze Mars store performance by joining sales, inventory, and labor tables, and return the key KPIs by store and week.

Use the provided tables and include weeks represented in any source table. Missing source values should not remove a store-week from the results.

Output

  1. One row per store and week, with store_id, week_start, net_sales, units_sold, avg_inventory_units, labor_hours, labor_cost, and sales_per_labor_hour.
  2. Include all store-weeks present in any source table, treating missing additive measures as zero where appropriate and returning NULL when labor hours are zero or unavailable.
  3. Order by store_id, then week_start.

Schema

sales
ColumnTypeDescription
sale_idPKINTUnique sales transaction identifier
store_idINTMars store identifier
sale_dateDATETransaction date
units_soldINTUnits sold in the transaction
net_salesDECIMAL(12,2)Net sales amount after discounts and returns
inventory
ColumnTypeDescription
inventory_idPKINTUnique inventory snapshot identifier
store_idINTMars store identifier
inventory_dateDATEInventory snapshot date
units_on_handINTUnits available at the snapshot time
inventory_valueDECIMAL(12,2)Estimated inventory value
labor
ColumnTypeDescription
labor_idPKINTUnique labor record identifier
store_idINTMars store identifier
labor_dateDATEShift or labor record date
labor_hoursDECIMAL(8,2)Hours worked
labor_costDECIMAL(12,2)Labor cost for the record
Tablessalesinventorylabor
Interviewer

Your question is Store KPI SQL Analysis. 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.