Write a SQL query to compare current-week and previous-week failure rates by plant and machine type.
Use inspection_events, joined with plants and machine_types. Treat Monday as the first day of the week. A failure rate is failed inspections divided by all inspections in the relevant week. Include machine groups with activity in either week, and treat missing weekly activity as a 0% rate.
Output
- One row per plant and machine type.
- Columns:
plant_name, machine_type, current_week_failure_rate, previous_week_failure_rate.
- Rates should be percentages rounded to two decimals, ordered by plant name and machine type.