SQL代码如下:
SELECT e.userno,e.fullname, COUNT(sp.id) pactct, SUM(sp.tamt) pactamt, COUNT(so.id)ordct, SUM(so.zhtamt) ordamt, COUNT(c.id)custct, COUNT(coct.id)CONCT, COUNT(po.id)porct, SUM(po.zhtamt) poram FROM hr_employee e LEFT JOIN scm_salepact sp ON sp.saler=e.id AND sp.shstate=2 AND sp.ctime >='2014-01-01' AND sp.ctime<='2014-12-31' LEFT JOIN scm_saleorder so ON so.saler=e.id AND so.shstate=2 AND so.ctime >='2014-01-01' AND so.ctime<='2014-12-31' LEFT JOIN crm_customer c ON c.creater=e.id AND c.ctime >='2014-01-01' AND c.ctime<='2014-12-31' LEFT JOIN crm_contactrecord coct ON coct.lxr=e.id AND coct.ptime >='2014-01-01' AND coct.ptime<='2014-12-31' LEFT JOIN scm_salepriceorder po ON po.creater=e.id AND po.shstate=2 AND po.ctime >='2014-01-01' AND po.ctime<='2014-12-31'
而运行的结果却是: