Chapter 8 · Window Functions
25. Rank Accounts by Balance Within Type
Hard40 XPFinance
The analytics team wants to rank accounts by balance within each account type. Return account id, account_type, balance, and a rank column. Use RANK() partitioned by account_type, ordered by balance descending.
Tables
- PKidINT
- FKcustomer_id→ customers.idINT
- account_typeTEXT
- balanceREAL
- currencyTEXT
- opened_atTEXT
- statusTEXT
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.