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
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
Sign up free to run your codeLog inLn 1
Run your query to see results here.