Operations Managers at a company need a location-level view of market operations performance. Write a PostgreSQL query using market locations, completed orders, and recorded order errors.
Use 2025-02-15 as the reporting date, and analyze completed orders whose completed_at falls within the preceding 30 days, including both boundary dates.
Requirements
- Return every market location, including locations with no qualifying completed orders.
- Calculate completed order count and average cycle time in minutes.
- Calculate error rate as the percentage of completed orders with at least one associated error. Return
0.00 when a location has no completed orders.
- Sort results alphabetically by location name.
Output details
- Return columns in this order:
location_name, completed_orders, average_cycle_time_minutes, and error_rate_percent.
- Round
average_cycle_time_minutes and error_rate_percent to two decimal places.
- Return
NULL for average_cycle_time_minutes when a location has no qualifying completed orders.
- Keep separate market-location rows even when multiple locations share the same
location_name.