select 
C.city,
sum(A.loan_amount) as total_loan_amount, 
round(SUM(A.loan_amount)/COUNT(distinct A.customer_id), 2) as average_loan_amount,
count(distinct A.customer_id) as total_customers,
MAX(distinct L.loan_type_name) as most_applied_loan_type

from loan_applications A

join customers C on C.customer_id = A.customer_id
join loan_application_types T on T.application_id = A.application_id
join loan_types L on L.loan_type_id = T.loan_type_id

group by C.city