AML & Fraud Analytics Path · Mission 3 of 30Starter

Active customers by state

JOIN + WHERE + GROUP BY to aggregate across two tables

Back to AML & Fraud Analytics

The Brief

Marcus WellerDirector of AML Operationsaml-ops

Compliance wants a state-by-state headcount of customers with at least one open account — they're sizing regional SAR review capacity. Join `aml_customers` to `aml_accounts`, keep only rows where the account's `status` is `'open'`, count distinct customers per state, and order from most to least. Don't double-count a customer who has two open accounts.

You'll practice

GROUP BYJOINWHERE

Tables & columns available

aml_customersdim10 columns
ColumnTypeKey
customer_idINTPK
first_nameTEXT
last_nameTEXT
date_of_birthTEXT
emailTEXT
phoneTEXT
stateTEXT
statusTEXT
onboarded_dateTEXT
last_kyc_refreshTEXT
aml_accountsdim6 columns
ColumnTypeKey
account_idINTPK
customer_idINTFK → aml_customers
product_typeTEXT
open_dateTEXT
close_dateTEXT
statusTEXT

Hints (3)

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

Hint 1

Start with an INNER JOIN on `customer_id` so you only keep customers who actually have an account row.

Hint 2

Filter accounts on `status = 'open'` in the WHERE clause. Don't put it in an ON clause — the semantics are the same here but WHERE is the convention for LEFT-JOIN-safe code later.

Hint 3

Use `COUNT(DISTINCT c.customer_id)` so a customer with both a checking AND savings account counts once. Group by `c.state`, order by the count descending.