Chapter 8 · Window Functions
37. Detect Payment Gaps Over 60 Days
Hard40 XPFinance
The collections team wants to find loan payments that came more than 60 days after the previous payment on the same loan. Use LAG to get the previous payment date, then compute the gap in days. Return loan_id, payment_date, prev_payment_date, and gap_days. Only include rows where gap_days > 60. Sort by gap_days descending.
Tables
- PKidINT
- FKloan_id→ loans.idINT
- payment_dateTEXT
- amountREAL
- principal_paidREAL
- interest_paidREAL
- remaining_balanceREAL
Need help?
Ask Sol
AI tutor — looks at your current query and nudges you, without spoiling the answer.
Solution
Try the hints first — solving it yourself is what makes it stick.