Consumer Lending Analyst Path · Mission 6 of 30Easy

Approval rate by product

Conditional aggregation (CASE WHEN inside SUM) to compute approval ratio per product

The Brief

Marcus HollandChief Credit Officerconsumer-lending

First number for the credit committee tomorrow. Compute the approval rate per loan product — `action_taken = 1` (Originated) divided by total applications, grouped by product. Four columns: `product_code`, `approved_count`, `total_apps`, `approval_rate` (rounded to 4 decimals). Sort by approval_rate descending, then product_code ascending for tie-break.

You'll practice

CASE aggregationRatio

Tables & columns available

lending_applicationsfact18 columns
ColumnTypeKey
app_idINTPK
customer_idINTFK → retail_customers
product_idINTFK → retail_products
application_dateTEXT
requested_amountREAL
requested_termINT
loan_purposeTEXT
action_takenINT
denial_reason_1INT
aus_recommendationTEXT
rate_spreadREAL
lien_statusINT
occupancyINT
ethnicityINT
raceINT
sexINT
age_bucketTEXT
property_tractTEXTFK → lending_geography
retail_productsdim6 columns
ColumnTypeKey
product_idINTPK
product_codeTEXT
product_nameTEXT
categoryTEXT
subcategoryTEXT
default_aprREAL

Hints (3)

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

Hint 1

The ratio is two pieces: a numerator counting only approved rows, a denominator counting all rows in the same group. Both can come out of one aggregation pass — that's what conditional aggregation is for.

Hint 2

Postgres truncates integer division silently — int / int returns int. Cast at least one side of the divide to NUMERIC (or multiply by 1.0) before the round, or your rates will all come back as zeros.

Hint 3

Four projected columns, four-decimal rounding. Two-key sort (rate desc, code asc) keeps the ranking deterministic when two products tie on rate.