Chapter 9 · Interview Level
49. Transaction Type Pivot by Account
Hard40 XPFinance
The analytics team wants a pivot-style report showing each account's total amount broken down by transaction type. Return account_id, total_deposits, total_withdrawals, total_transfers, total_fees, and total_interest. Use conditional aggregation. Sort by account_id. Limit to 30 rows.
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.