Retail Banking Operations Path · Mission 21 of 30Expert

Deposit balance by acquisition channel

Latest-snapshot pivot + multi-table customer attribute join

The Brief

Marcus ChenRetail Banking COOretail-ops

CFO wants to see the deposit book split by how the customer was acquired. Use the latest balance snapshot per account (ROW_NUMBER PARTITION BY account ORDER BY snapshot_date DESC, keep rn=1). Join through customers for `acquisition_channel`. Filter to Deposit category only. Three columns: `acquisition_channel`, `n_accounts` (distinct count), `deposit_balance` (rounded 2 decimals). Sort by acquisition_channel ascending.

You'll practice

Latest-snapshot pivotCustomer attribute join

Tables & columns available

retail_balance_dailyfact8 columns
ColumnTypeKey
snapshot_idINTPK
account_idINTFK → retail_accounts
snapshot_dateTEXT
ledger_balanceREAL
available_balanceREAL
interest_rateREAL
days_overdrawnINT
delinquency_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_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_productsdim10 columns
ColumnTypeKey
product_idINTPK
product_codeTEXT
product_nameTEXT
categoryTEXT
subcategoryTEXT
default_aprREAL
default_apyREAL
monthly_feeREAL
nsf_feeREAL
od_feeREAL

Hints (3)

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

Hint 1

Same latest-snapshot CTE pattern as M19: ROW_NUMBER PARTITION BY account_id ORDER BY snapshot_date DESC, then keep `rn = 1`. Collapses 90 daily rows down to one per account.

Hint 2

Walk: `latest` → `retail_accounts` → `retail_customers` (for acquisition_channel) → `retail_products` (for category filter). Filter `category = 'Deposit'` so loans and cards don't slip in.

Hint 3

GROUP BY acquisition_channel. COUNT DISTINCT account_id (defensive against join fanout), SUM the latest balance, ROUND to 2. Sort ascending by channel.