Write a query to find the top 3 manufacturing defects per facility over the last trailing 30 days at ATC Manufacturing.
Use the provided facility, defect type, and defect event data. Treat the trailing period as inclusive of today and the date 30 days before today. Break ties alphabetically by defect name, then by defect type ID.
Output
- One row per qualifying facility and defect type, with columns
facility_id, facility_name, defect_name, defect_count, and defect_rank.
- Include only the three highest-ranked defect types for each facility with events in the period.
- Sort by
facility_name, then defect_rank, then defect_name.