select b.pay_ability,concat(round(avg(is_laolai)*100,1),'%') as overdue_ratio
from
(SELECT agreement_id,customer_id,overdue_days,
case when overdue_days is not null then 1 else 0 end as is_laolai
from loan_tb) a 
left join customer_tb b
on a.customer_id=b.customer_id
group by pay_ability
order by overdue_ratio desc