select c.pay_ability, concat(round(count(a.overdue_days)*100/count(agreement_id),1),'%') AS overdue_ratio from loan_tb AS a join customer_tb AS c on a.customer_id=c.customer_id group by pay_ability order by overdue_ratio desc
很简单的多表查询,只要注意数据关系就好

select c.pay_ability, concat(round(count(a.overdue_days)*100/count(agreement_id),1),'%') AS overdue_ratio from loan_tb AS a join customer_tb AS c on a.customer_id=c.customer_id group by pay_ability order by overdue_ratio desc
很简单的多表查询,只要注意数据关系就好