Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL for Hub Performance
00:00
5 left

SQL for Hub Performance

MediumSQL · PostgreSQL

Problem

Write a SQL query to analyze hub performance by joining orders, deliveries, and inventory tables to calculate daily delivery TAT, wastage percentage, and stock-out rate.

Use completed deliveries for TAT, inventory quantities for wastage, and stock-out minutes over a 24-hour operating day. Include dates represented by any source table.

Output

  1. One row per hub and calendar date.
  2. Columns: hub_id, performance_date, avg_delivery_tat_minutes, wastage_percentage, and stock_out_rate.
  3. Include available hub-date combinations even when one metric has no source data. Sort by hub_id, then performance_date.

Schema

orders
ColumnTypeDescription
order_idPKINTUnique order identifier
hub_idVARCHAR(10)Fulfillment hub identifier
order_dateDATEDate the order was placed
deliveries
ColumnTypeDescription
delivery_idPKINTUnique delivery identifier
order_idINTRelated order identifier
dispatched_atTIMESTAMPTimestamp when the delivery was dispatched
delivered_atTIMESTAMPTimestamp when the order was delivered
statusVARCHAR(20)Delivery status
inventory
ColumnTypeDescription
inventory_idPKINTUnique inventory record identifier
hub_idVARCHAR(10)Inventory hub identifier
inventory_dateDATEInventory measurement date
opening_stockINTUnits available at the start of the day
received_qtyINTUnits received during the day
wastage_qtyINTUnits discarded during the day
stockout_minutesINTMinutes without available stock
Tablesordersdeliveriesinventory
Interviewer

Your question is SQL for Hub Performance. 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.