Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL for Production and Quality Rates
00:00
5 left

SQL for Production and Quality Rates

MediumSQL · PostgreSQL

Problem

Write a SQL query to calculate weekly production output, defect rate, and on-time shipment rate by plant and product line.

Use production_runs, shipments, and plants. Define the production week from production_date and the shipment week from promised_ship_date. Defect rate is defective units divided by produced units. On-time shipment rate is units shipped on or before the promised date divided by total units shipped. Include weeks represented by either production or shipments.

Output

  1. One row per plant, product line, and week.
  2. Return plant_name, product_line, week_start, production_output, defect_rate, and on_time_shipment_rate.
  3. Sort by plant name, product line, and week start ascending.

Schema

plants
ColumnTypeDescription
plant_idPKINTUnique plant identifier
plant_nameVARCHAR(100)Plant name
regionVARCHAR(50)Geographic region
production_runs
ColumnTypeDescription
run_idPKINTUnique production run identifier
plant_idINTPlant where production occurred
product_lineVARCHAR(80)Product line manufactured
production_dateDATEProduction date
units_producedINTUnits produced in the run
defect_unitsINTUnits identified as defective
shipments
ColumnTypeDescription
shipment_idPKINTUnique shipment identifier
plant_idINTPlant shipping the units
product_lineVARCHAR(80)Product line shipped
promised_ship_dateDATECustomer-promised shipment date
actual_ship_dateDATEActual shipment date
units_shippedINTUnits included in the shipment
Tablesplantsproduction_runsshipments
Interviewer

Your question is SQL for Production and Quality Rates. 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.