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

SQL Bottleneck Analysis

HardSQL · PostgreSQL

Problem

Write a SQL query to analyze warehouse performance by joining orders, inventory, and labor tables to identify bottlenecks and late shipments.

Return one row per warehouse and order date. Treat an order with no shipped date as late when it has a promised ship date. A bottleneck exists when the late rate is at least 50%, inventory shortage exists, or productivity is below 10 units per labor hour.

Output

  1. Columns: warehouse_id, metric_date, total_orders, late_shipments, late_rate, avg_fulfillment_days, shortage_units, units_per_labor_hour, bottleneck_flag
  2. Include every warehouse-date combination with orders, including missing inventory or labor data.
  3. Order by warehouse_id, then metric_date.

Schema

orders
ColumnTypeDescription
order_idPKINTUnique order identifier
warehouse_idVARCHAR(10)Warehouse processing the order
order_dateDATEDate the order was placed
promised_ship_dateDATECommitted shipment date
shipped_dateDATEActual shipment date
item_countINTNumber of items in the order
statusVARCHAR(20)Current order status
inventory
ColumnTypeDescription
inventory_idPKINTUnique inventory snapshot identifier
warehouse_idVARCHAR(10)Warehouse holding the inventory
inventory_dateDATEDate of the inventory snapshot
skuVARCHAR(20)Stock keeping unit
available_unitsINTUnits available to fulfill orders
requested_unitsINTUnits requested for the snapshot
labor
ColumnTypeDescription
labor_idPKINTUnique labor record identifier
warehouse_idVARCHAR(10)Warehouse where labor was recorded
labor_dateDATEDate labor was recorded
labor_hoursDECIMAL(8,2)Total labor hours
units_pickedINTUnits picked by the labor team
Tablesordersinventorylabor
Interviewer

Your question is SQL Bottleneck 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.