The risk team needs loans classified into risk tiers. Use CASE WHEN to assign a risk_tier: 'High Risk' if interest_rate > 15 or the loan has no payments, 'Medium Risk' if interest_rate between 8 and 15, 'Low Risk' otherwise. Return loan id, loan_type, interest_rate, principal, payment_count, and risk_tier. Sort by risk_tier, interest_rate DESC. Limit to 40.
Schema
🔑idINT
🔗customer_idINT
loan_typeTEXT
principalREAL
interest_rateREAL
term_monthsINT
start_dateTEXT
statusTEXT
postgresql
Run your query to see results
Press Ctrl + Enter to execute