Credit Risk & Banking Path · Mission 10 of 30Easy

Joint accounts — who’s the primary?

LEFT JOIN + GROUP BY to aggregate child rows onto a filtered parent

Back to Credit Risk & Banking

The Brief

Marcus WellerChief Data Officerdata-platform

Compliance wants a list of our top joint-capable customers by account footprint. Pull customers where `is_primary_only = 0` — these are folks who appear as a joint or authorized user on at least one account somewhere — and show their customer_id, first_name, last_name, and the count of accounts they currently own. Sort by count desc and by customer_id asc for tie-breaking. Top 10 only.

You'll practice

JOINPrimary vs authorized

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

LEFT JOIN, not JOIN — some joint-capable customers have zero booked accounts (they're on someone else's account, not their own), and an inner JOIN would silently drop them.

Hint 2

GROUP BY all three customer fields in the SELECT. `COUNT(a.account_id)` — counting the JOINed column — returns 0 for customers with no accounts. `COUNT(*)` would return 1 due to the LEFT JOIN padding row.

Hint 3

GROUP BY all three customer fields in the SELECT, COUNT the joined account_id (so zero-account customers come back as 0, not 1), filter is_primary_only = 0, then ORDER BY the count DESC with customer_id as a tiebreaker, LIMIT 10.