Chapter 8 · Window Functions
36. Top 3 Accounts by Balance Per Type
Hard40 XPFinance
Find the top 3 highest-balance active accounts for each account type. Use ROW_NUMBER() in a CTE, then filter for the top 3. Return account_type, id, balance, and the row number (rn). Sort by account_type, rn.
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.