How do you optimize database queries for performance?
Using the provided PostgreSQL tables, write an efficient query that calculates qualifying customer order totals for calendar year 2025. The query should include only completed orders, exclude incomplete customer or order relationships, and return customers whose total is at least 500.
Output
- One row per qualifying customer with
customer_id, customer_name, completed_order_count, and total_amount.
- Sort by
total_amount descending, then customer_id ascending.