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

SQL for Site Performance

HardSQL · PostgreSQL

Problem

Write an SQL query to analyze monthly operational performance by site, joining production, downtime, and staffing tables to identify the top underperforming locations.

Calculate performance using units produced per staffed hour. Include downtime as a supporting operational metric, and return the two lowest-performing sites for each month. Treat missing downtime as zero and use site ID to break performance ties.

Output

  1. One row per selected site and month with month_start, site_id, units_produced, downtime_hours, staffed_hours, units_per_staffed_hour, and underperformance_rank.
  2. Include up to two sites per month, ordered by month_start, then underperformance_rank, then site_id.

Schema

production
ColumnTypeDescription
production_idPKINTUnique production record identifier
site_idINTOperational site identifier
production_dateDATEDate of production activity
units_producedINTNumber of units produced
downtime
ColumnTypeDescription
downtime_idPKINTUnique downtime record identifier
site_idINTOperational site identifier
downtime_dateDATEDate downtime was recorded
downtime_hoursNUMERIC(8,2)Hours of downtime recorded
staffing
ColumnTypeDescription
staffing_idPKINTUnique staffing record identifier
site_idINTOperational site identifier
staffing_dateDATEDate staffed hours were recorded
staffed_hoursNUMERIC(8,2)Total employee hours assigned
Tablesproductiondowntimestaffing
Interviewer

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