Chapter 8 · Window Functions
45. Account Balance Volatility Ranking
Hard40 XPFinance
Rank accounts by balance volatility. Volatility is measured as the difference between the maximum and minimum balance_after values across all transactions for that account divided by the average balance_after. Return account_id, min_balance, max_balance, avg_balance (rounded to 2), volatility (rounded to 4), and volatility_rank using RANK(). Order by volatility_rank ascending.
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.