Becton Dickinson operations wants a quarterly view of which medical devices are produced in the highest volumes at each manufacturing plant. Assume the report runs on January 15, 2026, so the last quarter is October 1 through December 31, 2025.
Write a PostgreSQL query that returns the top three devices by total produced units for each plant.
Requirements
- Include only production runs dated from
2025-10-01 through 2025-12-31.
- Include only runs with
status = 'Completed'.
- Aggregate
units_produced by plant and device, treating NULL units as zero.
- Rank devices independently within each plant and return at most three per plant.
- Break production-volume ties alphabetically by device name, and sort the final output by plant name and rank.