001Level 1

Chapter 7 · CTEs

12. Customer Financial Summary with CTE

Hard40 XPFinance

Build a comprehensive customer financial summary using a CTE. First, compute the total balance across all accounts for each customer. Then, in the main query, join with customers to return first_name, last_name, total_balance, and the number of accounts. Only include customers with total_balance > 10000. Sort by total_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.

Peek at the solution?

You can still earn the XP afterwards by submitting a working query — but you'll learn more if you give it one more try.