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.
Output
- One row per qualifying customer with
customer_id, customer_name, segment, completed_order_total, and latest_completed_order_date.
- Include only active customers with an account and more than 1,000 in completed 2025 orders.
- Order by total descending, then customer ID ascending.