合并SQL 调优

SELECT le.equipcode,sum(case when wo.ordertype=0 then 1 else 0 END) as wxcount,sum(case when wo.ordertype=0 then wo.workcost else 0 END) as wxcost ,
sum(case when wo.ordertype=1 then 1 else 0 END) as yhcount,sum(case when wo.ordertype=1 then wo.workcost else 0 END)as yhcost
FROM LAYOUT_EQUIP le LEFT JOIN WORK_ORDER wo ON le.equipcode=wo.equipcode
WHERE
le.del_flag = 0 and wo.del_flag=0
group by le.equipcode
同一个表两个条件的统计
原文地址:https://www.cnblogs.com/chenweida/p/9555176.html