How would you optimize a SQL query that is running slowly?
Use the customers and orders tables to produce the requested result. The answer should preserve the required filters and aggregation while being suitable for performance analysis in PostgreSQL.
customer_id, customer_name, completed_order_count, and total_completed_amount.| Column | Type | Description |
|---|---|---|
| customer_idPK | VARCHAR(20) | Unique customer identifier |
| customer_name | VARCHAR(100) | Customer display name |
| Column | Type | Description |
|---|---|---|
| order_idPK | INT | Unique order identifier |
| customer_id | VARCHAR(20) | Customer associated with the order |
| order_date | DATE | Order creation date |
| status | VARCHAR(40) | Current order status |
| amount | NUMERIC(12,2) | Order amount |