Chapter 8 · Window Functions
31. Each Account as Percentage of Customer Total
Hard40 XPFinance
For each account, show what percentage it represents of its customer's total balance. Return customer_id, account_type, balance, customer_total (sum of all the customer's account balances), and pct_of_total rounded to 1 decimal. Only include active accounts. Sort by customer_id, then pct_of_total 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.