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: Production, Defects, On-Time
00:00
5 left

SQL: Production, Defects, On-Time

MediumSQL · PostgreSQL

Problem

Write a SQL query to calculate weekly production output, defect rate, and on-time delivery by plant from operational data.

Use the plants, production_batches, and delivery_records tables. Treat missing defect counts as zero, include production batches without a delivery record, and calculate each week from the production date.

Output

  1. One row per plant and production week.
  2. Columns: plant_name, week_start, total_units_produced, defect_rate_pct, and on_time_delivery_rate_pct.
  3. Include weeks with production but no delivery, return NULL when a rate has no valid denominator, and sort by plant name and week start.

Schema

plants
ColumnTypeDescription
plant_idPKINTUnique plant identifier
plant_nameVARCHAR(100)Plant name
regionVARCHAR(50)Geographic region of the plant
production_batches
ColumnTypeDescription
batch_idPKINTUnique production batch identifier
plant_idINTPlant that produced the batch
production_dateDATEDate production was completed
units_producedINTTotal units produced in the batch
defect_unitsINTUnits classified as defective
delivery_records
ColumnTypeDescription
delivery_idPKINTUnique delivery record identifier
batch_idINTProduction batch associated with the delivery
due_dateDATEPromised delivery date
delivered_dateDATEActual delivery date
Tablesplantsproduction_batchesdelivery_records
Interviewer

Your question is SQL: Production, Defects, On-Time. 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.