How would you optimize a slow-running SQL query involving multiple joins and aggregations?
Use the PostgreSQL tables provided to return completed orders from the first quarter of 2025. The query should calculate customer-level order counts and revenue while avoiding unnecessary row multiplication.
Output
- One row per qualifying customer with
customer_id, customer_name, region, total_orders, and total_revenue
- Include only customers with positive revenue from completed orders in the specified period
- Order by
total_revenue descending, then customer_id ascending