Select
c.city,
Sum(la.loan_amount) as total_loan_amount,
Round(Sum(la.loan_amount) / Count(DISTINCT la.customer_id),2) as average_loan_amount,
Count(DISTINCT la.customer_id) as total_customers,
Max(loan_type_name) as most_applied_loan_type
From
loan_applications la
Join customers c On la.customer_id = c.customer_id
Join loan_application_types lap On la.application_id = lap.application_id
Join loan_types lt On lap.loan_type_id = lt.loan_type_id
Group by
c.city
Order by
c.city
最简洁版本

京公网安备 11010502036488号