As of 2026-04-30: only payments with paid_date <= '2026-04-30' count, and partial payments for an installment add up. An installment is overdue when due_date < '2026-04-30' and the amount paid for it is less than amount_due. A loan's days past due (DPD) = days from its OLDEST overdue due_date to 2026-04-30. Bucket each loan: 'Current' (nothing overdue), '1-30', '31-60', '61-90', '90+'. Return bucket, loans and overdue_amount (sum of unpaid amounts of overdue installments, ROUND 2) for buckets that have loans, ordered Current, 1-30, 31-60, 61-90, 90+.
| Column | Type |
|---|---|
| loan_id | TEXT |
| installment_no | INTEGER |
| due_date | DATE |
| amount_due | REAL |
| loan_id | installment_no | due_date | amount_due |
|---|---|---|---|
| L1 | 1 | 2026-01-05 | 1000 |
| L1 | 2 | 2026-02-05 | 1000 |
| L1 | 3 | 2026-03-05 | 1000 |
| L1 | 4 | 2026-04-05 | 1000 |
| L1 | 5 | 2026-05-05 | 1000 |
| L2 | 1 | 2026-01-05 | 1000 |
| L2 | 2 | 2026-02-05 | 1000 |
| L2 | 3 | 2026-03-05 | 1000 |
| Column | Type |
|---|---|
| payment_id | INTEGER |
| loan_id | TEXT |
| installment_no | INTEGER |
| paid_date | DATE |
| amount_paid | REAL |
| payment_id | loan_id | installment_no | paid_date | amount_paid |
|---|---|---|---|---|
| 1 | L1 | 1 | 2026-01-05 | 1000 |
| 2 | L1 | 2 | 2026-02-04 | 1000 |
| 3 | L1 | 3 | 2026-03-05 | 1000 |
| 4 | L1 | 4 | 2026-04-06 | 1000 |
| 5 | L2 | 1 | 2026-01-05 | 1000 |
| 6 | L2 | 2 | 2026-02-05 | 1000 |
| 7 | L3 | 1 | 2026-01-05 | 1000 |
| 8 | L3 | 2 | 2026-02-05 | 1000 |
| bucket | loans | overdue_amount |
|---|---|---|
| Current | 1 | 0 |
| 1-30 | 1 | 600 |
| 31-60 | 1 | 2000 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ As-Of Price Join for Trade Valuation · MRR Movements: New, Expansion, Contraction, Churn ›
{{ totalCount }} questions in the style asked at Amazon, Microsoft, Google, Meta, Flipkart and more — {{ hardPct }}% Hard. Write SQL in a real database engine in your browser, run it on sample data, then evaluate against hidden tests.
Company tags show where this type of question is commonly reported in interviews. Questions, data and solutions are written by TechTown.
{{ cur.statement }}
No submissions yet. Press Evaluate to submit your query.
{{ solutionSql }}
{{ out.error }}
You have solved your 3 free questions — nice work! Log in (free) to unlock all 150 questions, keep your streak and appear on the leaderboard.