How would you optimize a slow-running SQL query in Azure SQL Database?
Asked in the technical interview stage. Azure Data Engineer, 4-5 yrs exp.
For grading, use customers, orders, order_items, and products. Return completed orders from the first quarter of 2025 for products in the Home Care category, including only customers whose category spend exceeds 100.
customer_id, customer_name, order_count, and total_spend.total_spend descending, then customer_id ascending.| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Customer identifier |
| customer_name | VARCHAR(100) | Customer display name |
| region | VARCHAR(50) | Customer region |
| status | VARCHAR(20) | Customer account status |
| Column | Type | Description |
|---|---|---|
| order_idPK | INT | Order identifier |
| customer_id | INT | Customer who placed the order |
| order_date | DATE | Date the order was placed |
| order_status | VARCHAR(20) | Order processing status |
| Column | Type | Description |
|---|---|---|
| order_item_idPK | INT | Order line identifier |
| order_id | INT | Referenced order |
| product_id | INT | Referenced product |
| quantity | INT | Units purchased |
| unit_price | NUMERIC(10,2) | Price per unit |
| Column | Type | Description |
|---|---|---|
| product_idPK | INT | Product identifier |
| product_name | VARCHAR(100) | Product name |
| category | VARCHAR(50) | Product category |