Chapter 8 · Window Functions
38. Account Balance Quartile Classification
Hard40 XPFinance
The analytics team wants to divide all active accounts into 4 equal quartiles based on balance. Use a CTE to first assign quartiles with NTILE(4), then compute the min and max balance per quartile. Return account id, account_type, balance, balance_quartile, quartile_min, and quartile_max. Sort by balance DESC.
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.