Chapter 6 · Subqueries
23. Account Balance Change Since Opening
Medium20 XPFinance
For each active account, compute the net change in balance by summing all transaction amounts. Return account id, account_type, current balance, net_transaction_total (sum of all transaction amounts), and the difference. Sort by the difference descending. Limit to 20.
Tables
- PKidINT
- FKcustomer_id→ customers.idINT
- account_typeTEXT
- balanceREAL
- currencyTEXT
- opened_atTEXT
- statusTEXT
- 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.