Write a SQL query to analyze operational performance by region and month, joining orders, shipments, and returns tables to identify bottlenecks.
Use the available records for all orders, including orders without shipments or returns. Define a bottleneck using shipment coverage, average delivery time, and return rate.
Output
- One row per region and order month.
- Columns:
region, month, orders_count, shipped_orders, returned_orders, shipment_rate_pct, return_rate_pct, avg_delivery_days, bottleneck_score, bottleneck_reason, and prior_month_score.
- Include all order months, sort by
region and month, and use NULL when a region has no prior month.