select a.education_sn,
SUM(if(c.pay_type = 0,c.pay_fee,0)) as educ_fee,
SUM(if(c.pay_type = 1,c.pay_fee,0)) as filing_fee,
SUM(if(c.pay_type = 2,c.pay_fee,0)) as collect_fee,
SUM(if(c.pay_type = 3,c.pay_fee,0)) as guidance_fee
from ah_education as a
JOIN ah_pay as c on a.eid = c.eid where a.is_delete = 0and a.eid = 107GROUPby a.education_sn;
求和(原始)2: 查询同一个表同一字段不同类型
select a.education_sn,
( selectSUM(pay_fee) from ah_pay where pay_type = 0and eid = 107 ) as educ_fee ,
( selectSUM(pay_fee) from ah_pay where pay_type = 1and eid = 107 ) as filing_fee ,
( selectSUM(pay_fee) from ah_pay where pay_type = 2and eid = 107 ) as collect_fee ,
( selectSUM(pay_fee) from ah_pay where pay_type = 3and eid = 107 ) as guidance_fee
from ah_education as a
JOIN ah_pay as c on a.eid = c.eid where a.is_delete = 0and a.eid = 107GROUPby a.education_sn