Retail Banking Operations Path · Mission 25 of 30Expert

Customer 360 — top depositors

Conditional COUNT pivot + multi-CTE assembly

The Brief

Sarah ReyesCustomer Insights Leadretail-ops

Build the per-customer Customer 360 row for the top 5 depositors (Active customers only, by total deposit balance). Latest snapshot per account. Eight columns: `customer_id`, `household_id`, `account_count` (open accounts only), `n_checking`, `n_savings` (treat 'savings' miscased as Savings), `n_cards`, `n_loans`, `total_deposits` (rounded 2 decimals). Sort by total_deposits descending, then customer_id ascending. LIMIT 5.

You'll practice

Conditional COUNT pivotMulti-CTE

Tables & columns available

retail_customersdim13 columns
ColumnTypeKey
customer_idINTPK
household_idTEXT
first_nameTEXT
last_nameTEXT
date_of_birthTEXT
stateTEXT
segmentTEXT
fico_currentINT
estimated_incomeREAL
kyc_riskTEXT
acquisition_channelTEXT
onboarded_dateTEXT
statusTEXT
retail_accountsdim13 columns
ColumnTypeKey
account_idINTPK
customer_idINTFK → retail_customers
product_idINTFK → retail_products
branch_idINTFK → retail_branches
open_dateTEXT
close_dateTEXT
statusTEXT
ownership_typeTEXT
interest_rateREAL
original_balanceREAL
credit_limitREAL
fico_at_origINT
maturity_dateTEXT
retail_productsdim10 columns
ColumnTypeKey
product_idINTPK
product_codeTEXT
product_nameTEXT
categoryTEXT
subcategoryTEXT
default_aprREAL
default_apyREAL
monthly_feeREAL
nsf_feeREAL
od_feeREAL
retail_balance_dailyfact8 columns
ColumnTypeKey
snapshot_idINTPK
account_idINTFK → retail_accounts
snapshot_dateTEXT
ledger_balanceREAL
available_balanceREAL
interest_rateREAL
days_overdrawnINT
delinquency_statusTEXT

Hints (3)

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

Hint 1

Pre-aggregate the latest balance per account in a CTE (ROW_NUMBER PARTITION BY account ORDER BY snapshot_date DESC, keep rn=1). Then LEFT JOIN that to `retail_accounts` filtered to status='Open'.

Hint 2

Conditional COUNT pivots — COUNT DISTINCT account_id wrapped in a CASE that filters to the right subcategory. Watch the savings miscasing trap: LOWER on subcategory collapses 'Savings' and 'savings' into one count.

Hint 3

Outer SELECT groups by customer_id and household_id. ORDER BY total_deposits descending with customer_id ascending as the tiebreaker, then LIMIT to the top depositors the briefing asked for.