Your question is Optimize Slow SQL on Large DB. Start with the requirements and the three tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
How do you optimize a SQL query that is running slowly on a very large database?
Use the provided PostgreSQL schema as the working example. Produce the result for completed orders from the first quarter of 2025, and explain how you would investigate and improve performance at scale.
customer_id, customer_name, region, order_count, and total_revenue.total_revenue descending, then customer_id ascending.| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Unique customer identifier |
| customer_name | VARCHAR(100) | Customer name |
| region | VARCHAR(50) | Customer region |
| Column | Type | Description |
|---|---|---|
| order_idPK | INT | Unique order identifier |
| customer_id | INT | Customer who placed 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 ordered |
| unit_price | NUMERIC(10,2) | Price per unit |