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
- 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.
- Include up to two sites per month, ordered by
month_start, then underperformance_rank, then site_id.