Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Site Performance SQL Analysis
00:00
5 left

Site Performance SQL Analysis

HardSQL · PostgreSQL

Problem

Write a SQL query to analyze operational performance by CRH site, including monthly output, defect rate, and year-over-year change. Use the provided CRH site, production batch, and inspection data. Include months with production records, handle missing inspection data and zero output safely, and compare each month with the same month in the prior year.

Output

  1. One row per CRH site and production month.
  2. Columns: site_code, month, monthly_output, defect_rate, and yoy_output_change_pct.
  3. Sort by site_code, then month ascending. Return NULL when a prior-year comparison or valid defect-rate denominator is unavailable.

Schema

sites
ColumnTypeDescription
site_idPKINTUnique CRH site identifier
site_codeVARCHAR(20)Short CRH site code
site_nameVARCHAR(100)CRH site name
regionVARCHAR(50)Operational region
production_batches
ColumnTypeDescription
batch_idPKINTUnique production batch identifier
site_idINTCRH site responsible for the batch
production_dateDATEBatch production date
output_unitsINTUnits produced in the batch
quality_inspections
ColumnTypeDescription
inspection_idPKINTUnique inspection identifier
batch_idINTInspected production batch
inspection_dateDATEDate of quality inspection
defective_unitsINTUnits identified as defective
Tablessitesproduction_batchesquality_inspections
Interviewer

Your question is Site Performance SQL Analysis. 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.