Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Store Performance SQL Join
00:00
5 left

Store Performance SQL Join

MediumSQL · PostgreSQL

Problem

Write a SQL query to analyze LEGO Group store performance by joining sales, inventory, and staffing tables to identify locations with low stock and declining revenue. Use the latest sales month for the comparison. Treat a location as low stock when total stock is below its total reorder level, and include the latest available staffing data for each location.

Output

  1. One row per qualifying LEGO Group store.
  2. Columns: store_id, current_revenue, prior_revenue, revenue_change_pct, stock_units, reorder_level, employee_count, and scheduled_hours.
  3. Include only stores with lower latest-month revenue and low stock. Order by revenue_change_pct ascending, then store_id.

Schema

sales
ColumnTypeDescription
sale_idPKINTEGERUnique sales record identifier
store_idVARCHAR(20)LEGO Group store identifier
sale_monthDATEFirst day of the sales month
revenueNUMERIC(12,2)Revenue recorded by the sales row
inventory
ColumnTypeDescription
inventory_idPKINTEGERUnique inventory record identifier
store_idVARCHAR(20)LEGO Group store identifier
skuVARCHAR(30)LEGO product SKU
stock_unitsINTEGERUnits currently in stock
reorder_levelINTEGERMinimum desired units before replenishment
staffing
ColumnTypeDescription
staffing_idPKINTEGERUnique staffing record identifier
store_idVARCHAR(20)LEGO Group store identifier
staff_monthDATEMonth covered by the staffing record
employee_countINTEGERNumber of employees assigned to the store
scheduled_hoursNUMERIC(10,2)Scheduled staff hours for the month
Tablessalesinventorystaffing
Interviewer

Your question is Store Performance SQL Join. 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.