Retail Banking Operations Path · Mission 19 of 30Hard

Loan-to-Deposit ratio by region

Conditional aggregation across product categories with latest-snapshot ROW_NUMBER

The Brief

Jordan KimTreasurerretail-ops

Quarterly board pack. I need Loan-to-Deposit ratio by region — using the latest balance snapshot per account. From `retail_balance_daily`, pick `rn=1` per account (ROW_NUMBER PARTITION BY account ORDER BY snapshot_date DESC). Join to `retail_accounts` → `retail_branches` for region and `retail_products` for category. Pivot Loan vs Deposit balances per region with conditional SUM. Five columns: `region`, `deposit_balance`, `loan_balance`, `ldr_pct` (loan ÷ deposit × 100, rounded to 1 decimal). Sort by region ascending.

You'll practice

Cross-product aggregation

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_branchesdim8 columns
ColumnTypeKey
branch_idINTPK
branch_nameTEXT
regionTEXT
stateTEXT
lmi_tract_flagINT
open_dateTEXT
close_dateTEXT
branch_typeTEXT
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

Latest snapshot per account: ROW_NUMBER PARTITION BY account ORDER BY snapshot_date DESC, then keep only the rn=1 row. Collapses many daily rows down to one current balance per account.

Hint 2

Pivot Deposit vs Loan into separate columns with conditional SUM (CASE inside the SUM). Round the dollar columns to 2 decimals.

Hint 3

LDR is loans divided by deposits, multiplied by 100, rounded to 1. NULLIF the denominator so a region with zero deposits doesn't crash the division. Card category isn't in scope here.