select c.pay_ability,
concat(round(sum(case
when l.overdue_days is not null then 1
else 0
end)/count(*)*100,1),'%') as overdue_ratio
from loan_tb l
inner join customer_tb c
on l.customer_id = c.customer_id
group by c.pay_ability
ORDER BY
overdue_ratio DESC
感觉 case when用的相当不熟练,需要加强练习



京公网安备 11010502036488号