Chapter 8 · Window Functions
29. Account Balance Quartiles
Hard40 XPFinance
The analytics team wants to segment accounts into four balance quartiles. Use NTILE(4) to assign each account to a quartile based on balance. Return id, account_type, balance, and quartile. Only include active accounts. Order 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.