Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Weekly Order Accuracy SQL
00:00
5 left

Weekly Order Accuracy SQL

MediumSQL · PostgreSQL

Problem

Write a SQL query to analyze weekly order accuracy and missing-item rates by fulfillment center using orders, order_items, and complaints tables.

Use all available order dates. Treat an order as accurate when it has no complaint. Treat a missing-item rate as missing units divided by ordered units. Label orders without a fulfillment center as Unknown.

Output

  1. One row per calendar week and fulfillment center
  2. Columns: week_start, fulfillment_center, total_orders, accurate_orders, accuracy_rate_pct, total_units, missing_units, and missing_item_rate_pct
  3. Include centers with no complaints and avoid counting an order or item more than once
  4. Sort by week_start, then fulfillment_center

Schema

orders
ColumnTypeDescription
order_idPKINTUnique order identifier
order_dateDATEDate the order was placed
fulfillment_centerVARCHAR(50)Fulfillment center handling the order
order_statusVARCHAR(30)Current order status
order_items
ColumnTypeDescription
item_idPKINTUnique order-item identifier
order_idINTOrder containing the item
item_nameVARCHAR(100)CookUnity meal or item name
quantityINTUnits ordered for the item
complaints
ColumnTypeDescription
complaint_idPKINTUnique complaint identifier
order_idINTOrder associated with the complaint
item_idINTSpecific item associated with the complaint, when available
complaint_typeVARCHAR(40)Complaint category
missing_quantityINTUnits reported missing for a missing-item complaint
Tablesordersorder_itemscomplaints
Interviewer

Your question is Weekly Order Accuracy SQL. 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.