Chapter 8 · Window Functions
33. 3-Transaction Moving Average
Hard40 XPFinance
The analytics team wants a 3-transaction moving average of amounts for account_id = 151. For each transaction, compute the average of the current and two preceding transactions. Return transaction_date, amount, and moving_avg rounded to 2 decimals. Order by 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.