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.
customer_id, customer_name, region, total_orders, and total_revenuetotal_revenue descending, then customer_id ascending| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Unique customer identifier |
| customer_name | VARCHAR(100) | Customer display name |
| region | VARCHAR(50) | Customer geographic region |
| Column | Type | Description |
|---|---|---|
| order_idPK | INT | Unique order identifier |
| customer_id | INT | Customer associated with the order |
| order_date | DATE | Date the order was placed |
| status | VARCHAR(20) | Order processing status |
| Column | Type | Description |
|---|---|---|
| order_item_idPK | INT | Unique order line identifier |
| order_id | INT | Order containing the item |
| quantity | INT | Number of units on the order line |
| unit_price | NUMERIC(10,2) | Price per unit |