Chapter 9 · Interview Level
46. Monthly Deposits vs Withdrawals
Hard40 XPFinance
The treasury team needs a monthly comparison of total deposits vs total withdrawals. For each month (YYYY-MM), compute total_deposits and total_withdrawals using conditional aggregation. Also compute net_flow (deposits minus withdrawals). Sort by month.
Tables
- PKidINT
- FKaccount_id→ accounts.idINT
- transaction_dateTEXT
- typeTEXT
- amountREAL
- balance_afterREAL
- descriptionTEXT
- reference_numberTEXT
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.