Write a SQL query to find the average downtime of machines across different production plants.
Use the plants, machines, and downtime_events tables. Include every plant, including plants without recorded downtime, and ignore missing downtime durations.
Output
- One row per plant with
plant_name and average_downtime_minutes
- Include plants with no valid downtime records, using
NULL for their average
- Sort by average downtime descending, place
NULL values last, and break ties by plant name ascending.
Output details
- Round
average_downtime_minutes to exactly 2 decimal places.
- Treat plants as distinct by
plant_id, retaining separate rows when multiple plants share the same plant_name.