HelloFresh operations analysts monitor weekly delivery reliability across fulfillment periods. Write a PostgreSQL query that calculates the percentage of late deliveries for each calendar week and a three-week rolling average of that percentage.
calendar_weeks to deliveries using each delivery's delivery_date and the week's date range.delivered_at is later than promised_at. Treat undelivered records as not yet classifiable and exclude them from the late count, but include them in total deliveries.0 for those weeks.| Column | Type | Description |
|---|---|---|
| delivery_idPK | INT | Unique delivery identifier |
| delivery_date | DATE | Date assigned to the delivery |
| promised_at | TIMESTAMP | Promised delivery timestamp |
| delivered_at | TIMESTAMP | Actual delivery timestamp |
| delivery_channel | VARCHAR(20) | Delivery channel |
| Column | Type | Description |
|---|---|---|
| week_startPK | DATE | Inclusive start of the reporting week |
| week_end | DATE | Exclusive end of the reporting week |