Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
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
Sign up free to run your codeLog inLn 1
Run your query to see results here.