Chapter 5 · JOINs
31. Total Balance Per Customer
Medium20 XPFinance
The wealth report needs the total balance across all accounts for each customer. Return first_name, last_name, and total_balance (sum of all account balances). Only include customers with active accounts. Sort by total_balance descending. Limit to top 20.
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.