Chapter 8 · Window Functions
30. Dense Rank Customers by Total Balance
Hard40 XPFinance
Rank customers by their total account balance using DENSE_RANK. First compute the total balance across all active accounts per customer, then assign a dense rank. Return first_name, last_name, total_balance, and balance_rank. Show top 20 by rank.
Tables
- PKidINT
- first_nameTEXT
- last_nameTEXT
- emailTEXT
- phoneTEXT
- date_of_birthTEXT
- cityTEXT
- stateTEXT
- countryTEXT
- created_atTIMESTAMP
- 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.