Tell me about a time you used SQL window functions to solve a business problem, and walk me through your approach step by step.
Use the customers, loans, and payments tables. Return monthly metrics for completed payments only. Include rows with NULL payment amounts and treat those amounts as zero.
Output
- One row per loan and payment month.
- Columns:
loan_id, customer_name, payment_month, monthly_paid, payment_count, previous_month_paid, and cumulative_paid.
- Exclude months without completed payments. Order by
loan_id, then payment_month ascending.