The collections team wants to see each loan payment alongside the next scheduled payment date. For each payment, use LEAD to get the next payment_date on the same loan. Return loan_id, payment_date, amount, next_payment_date, and days_until_next (difference in days). Filter to loan_id = 1 for readability. Order by payment_date.
Schema
🔑idINT
🔗loan_idINT
payment_dateTEXT
amountREAL
principal_paidREAL
interest_paidREAL
remaining_balanceREAL
postgresql
Run your query to see results
Press Ctrl + Enter to execute