Credit Risk & Banking Path · Mission 4 of 30Starter

Active deposit customers by state

GROUP BY + JOIN + ORDER BY to produce a segmented count

Back to Credit Risk & Banking

The Brief

Sofia DelacroixHead of Consumer Marketingconsumer-marketing

Planning the Q2 direct-mail drop. I need the count of active deposit customers by state. Deposit = Checking or Savings. Active = account status is `Open`. Show `state` and a count column called `n_customers`, sorted highest to lowest. Distinct customers — not accounts. One person in two states doesn't exist in our data model.

You'll practice

GROUP BYJOINORDER BY

Tables & columns available

banking_customersdim7 columns
ColumnTypeKey
customer_idINTPK
first_nameTEXT
last_nameTEXT
date_of_birthTEXT
stateTEXT
onboarded_dateTEXT
is_primary_onlyINT
banking_accountsdim8 columns
ColumnTypeKey
account_idINTPK
customer_idINTFK → banking_customers
product_typeTEXT
open_dateTEXT
close_dateTEXT
credit_limitREAL
current_ficoINT
statusTEXT

Hints (3)

Each hint you reveal reduces the XP you can earn. Try the query first.

Hint 1

Customer state data and account product type are in separate tables. You want only customers with active deposit products — think about which account types qualify as "deposits" and how to connect them to the customer geography.

Hint 2

Filter: `a.product_type IN ('Checking','Savings')` and `a.status = 'Open'`.

Hint 3

`GROUP BY c.state`, `SELECT c.state, COUNT(DISTINCT c.customer_id) AS n_customers`, `ORDER BY n_customers DESC`. COUNT(DISTINCT ...) because a customer with both a Checking AND a Savings account would otherwise be counted twice.