Chapter 6 · Subqueries
26. Customers Who Have Multiple Active Loans
Medium20 XPFinance
The credit risk team needs to find customers who have more than one active loan. Use a subquery with GROUP BY and HAVING to identify qualifying customer_ids, then join to customers for details. Return first_name, last_name, and the number of active loans (active_loan_count). Sort by active_loan_count descending.
Tables
- PKidINT
- first_nameTEXT
- last_nameTEXT
- emailTEXT
- phoneTEXT
- date_of_birthTEXT
- cityTEXT
- stateTEXT
- countryTEXT
- created_atTIMESTAMP
- PKidINT
- FKcustomer_id→ customers.idINT
- loan_typeTEXT
- principalREAL
- interest_rateREAL
- term_monthsINT
- start_dateTEXT
- statusTEXT
Need help?
Ask Sol
AI tutor — looks at your current query and nudges you, without spoiling the answer.
Solution
Try the hints first — solving it yourself is what makes it stick.