Write a SQL query to analyze operational performance by joining order, shipment, and customer tables, then calculate delivery time, late shipment rate, and monthly trends.
Use the provided tables and include orders without shipments. Treat a shipment as late when its delivery date is after the promised delivery date. Calculate metrics by order month and customer region.
Output
- One row per order month and region
- Columns:
month_start, region, orders_count, delivered_shipments, avg_delivery_days, late_shipments, and late_shipment_rate
- Include undelivered and regionless orders, and sort by
month_start, then region