Your question is SQL Rolling Defect Rate Query. Start with the requirements and the two 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.
Mercedes-Benz Group operations teams need a daily quality metric across active manufacturing lines. Write a PostgreSQL query that calculates the overall defect rate for each production date and its rolling seven-day average.
is_active = FALSE or NULL must be excluded.| Column | Type | Description |
|---|---|---|
| line_idPK | INTEGER | Manufacturing line identifier |
| line_name | VARCHAR(100) | Mercedes-Benz production line name |
| plant_code | VARCHAR(20) | Manufacturing plant code |
| is_active | BOOLEAN | Whether the line is currently active |
| Column | Type | Description |
|---|---|---|
| production_idPK | INTEGER | Production record identifier |
| line_id | INTEGER | Manufacturing line associated with the record |
| production_date | DATE | Production date |
| units_produced | INTEGER | Units produced on the line |
| defective_units | INTEGER | Units identified as defective |
| maintenance_note | TEXT | Optional production or maintenance note |