Chapter 8 · Window Functions
39. Running Balance After Each Transaction
Hard40 XPFinance
For account_id = 151, compute a running sum of transaction amounts ordered by transaction_date. Return the row number, transaction_date, type, amount, and running_total using a SUM window function with an appropriate frame (ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW). Sort by transaction_date.
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.