Chapter 9 · Interview Level
24. Average Days Between Loan Payments
Medium20 XPFinance
For each loan that has at least 2 payments, calculate the average number of days between consecutive payments. Return loan_id, payment_count, and avg_days_between (rounded to 1 decimal). Use the difference between the earliest and latest payment dates divided by (payment_count - 1). Order by avg_days_between ascending.
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.