Write a SQL query to analyze shipment performance by site at Maersk, including on-time delivery rate and average delay by month.
Use the sites and shipments tables. Include delivered shipments with a non-null promised delivery timestamp. A shipment is on time when it is delivered on or before the promised timestamp. Average delay should count early or on-time shipments as zero delay.
site_name, delivery_month, shipment_count, on_time_delivery_rate, and average_delay_days.| Column | Type | Description |
|---|---|---|
| site_idPK | INT | Unique Maersk site identifier |
| site_name | VARCHAR(100) | Maersk site or terminal name |
| Column | Type | Description |
|---|---|---|
| shipment_idPK | INT | Unique shipment identifier |
| site_id | INT | Site responsible for the shipment |
| promised_delivery_at | TIMESTAMP | Promised delivery timestamp |
| delivered_at | TIMESTAMP | Actual delivery timestamp |