Chapter 8 · Window Functions
28. Previous Transaction Amount
Hard40 XPFinance
The fraud detection team wants to compare each transaction to the previous one on the same account. For account_id = 151, return transaction_date, amount, the previous transaction amount (prev_amount using LAG), and the difference. 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.