Write a SQL query to analyze production performance by line, shift, and day, including output, waste, and downtime metrics at Stouffers. Use completed production runs and the provided line and shift reference data.
Output
- One row per line, shift, and production day with valid reference matches.
- Columns:
line_name, shift_name, production_day, output_units, waste_units, downtime_minutes, and waste_percentage.
- Include totals for each combination, calculate waste as a percentage of output plus waste, and sort by line, shift, and day.
Output details
- Sort
line_name, shift_name, and production_day in ascending order.
- Round
waste_percentage to two decimal places.
- Treat NULL
waste_units and downtime_minutes as zero before totaling.
- Return
waste_percentage as NULL when output_units + waste_units equals zero.