Chapter 9 · Interview Level
23. Combined Cash Inflow Report
Medium20 XPFinance
The treasury team wants a unified view of all cash inflows: deposit transactions and loan payments. Use UNION ALL to combine deposit transactions (with source = 'deposit') and loan payments (with source = 'loan_payment'). Return source, the date (transaction_date or payment_date), and amount. Sort by date (newest first), then source, then amount (highest first). Limit to 50.
Tables
- PKidINT
- FKaccount_id→ accounts.idINT
- transaction_dateTEXT
- typeTEXT
- amountREAL
- balance_afterREAL
- descriptionTEXT
- reference_numberTEXT
- 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.