Your question is Top Devices Per Plant Query. Start with the requirements and the three tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
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.
2025-10-01 through 2025-12-31.status = 'Completed'.units_produced by plant and device, treating NULL units as zero.| Column | Type | Description |
|---|---|---|
| plant_idPK | INTEGER | Manufacturing plant identifier |
| plant_name | VARCHAR(100) | Manufacturing plant name |
| city | VARCHAR(100) | Plant city |
| region | VARCHAR(50) | Operating region |
| Column | Type | Description |
|---|---|---|
| device_idPK | INTEGER | Medical device identifier |
| device_name | VARCHAR(150) | BD medical device name |
| device_category | VARCHAR(100) | Device category |
| Column | Type | Description |
|---|---|---|
| run_idPK | INTEGER | Production run identifier |
| plant_id | INTEGER | References plants.plant_id |
| device_id | INTEGER | References devices.device_id |
| production_date | DATE | Date of the production run |
| units_produced | INTEGER | Number of devices produced |
| status | VARCHAR(20) | Production run status |