Chapter 8 · Window Functions
40. Dense Rank Transactions by Amount per Account Type
Hard40 XPFinance
Rank all transactions by amount within their account's type using DENSE_RANK. Join transactions to accounts. Return account_type, transaction id, amount, and the dense_rank. Only include the top 5 ranked transactions per account type. Sort by account_type, then rank.
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.