What is your approach to optimizing slow-running SQL queries or ETL jobs?
For this hands-on exercise, write PostgreSQL SQL that returns premium totals for active policies during 2025. Your solution should demonstrate an optimization-minded approach, including early filtering and appropriate handling of policies without qualifying payments.
Output
- One row per active policy issued before 2026-01-01.
- Columns:
policy_id, customer_name, product_name, total_successful_premium, and latest_successful_payment.
- Include policies with no successful 2025 payments, showing zero and NULL respectively. Order by
policy_id ascending.