Write a SQL query to track weekly order volume, average delivery time, and on-time rate by city and kitchen, and identify the top underperforming locations.
Use completed delivered orders only. Define a week using the Monday starting date, calculate delivery time in minutes, and include locations with at least two completed orders in a week. Return the two lowest-performing locations per week.
Output
- One row per selected week, city, and kitchen.
- Columns:
week_start, city, kitchen_name, order_volume, avg_delivery_minutes, on_time_rate, and underperformance_rank.
- On-time rate is a percentage where delivery at or before the promised time is on time.
- Order by
week_start, underperformance_rank, and kitchen_name.