Chapter 5 · JOINs
48. Average Balance by Branch City
Medium20 XPFinance
Compare average account balances across branch cities. Join customers to accounts using customer_id, then group by the customer's city. Return city, the number of accounts (num_accounts), and the average balance (avg_balance, rounded to 2 decimals). Only include cities with at least 3 accounts. Order by avg_balance descending.
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.