Your question is Optimize SQL Queries. 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 SQL queries?
Demonstrate your approach by writing an efficient PostgreSQL query for the provided customer, account, and order data. Return active customers whose completed orders during 2025 exceed the stated threshold, and briefly explain performance considerations.
customer_id, customer_name, segment, completed_order_total, and latest_completed_order_date.| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Unique customer identifier |
| customer_name | VARCHAR(100) | Customer display name |
| account_id | INT | Linked account identifier |
| status | VARCHAR(20) | Customer lifecycle status |
| Column | Type | Description |
|---|---|---|
| account_idPK | INT | Unique account identifier |
| account_name | VARCHAR(100) | Account name |
| segment | VARCHAR(30) | Account market segment |
| Column | Type | Description |
|---|---|---|
| order_idPK | INT | Unique order identifier |
| customer_id | INT | Customer who placed the order |
| order_date | DATE | Order creation date |
| status | VARCHAR(20) | Order processing status |
| total_amount | NUMERIC(12,2) | Order total amount |