|
楼主 |
发表于 2010-11-1 10:59
|
显示全部楼层
以下我的这个查询,哪个高手给优化以下,写的太长了。
SELECT C.系统区域划分, Nz(D.月末客户经理,0) AS 月末客户经理, Nz(E.月末渠道联系人,0) AS 月末渠道联系人, Nz(A.新增客户经理,0) AS 新增客户经理, Nz(G.新增渠道联系人,0) AS 新增渠道联系人, Nz(H.修改客户经理,0) AS 修改客户经理, Nz(i.修改渠道联系人,0) AS 修改渠道联系人, J.删除客户经理, K.删除渠道联系人, L.经理评级, M.经理未评级
FROM ((((((((((((Select 系统区域划分 From D201009 UNION Select 系统区域划分 From D201010 Group By 系统区域划分) AS C LEFT JOIN (SELECT 系统区域划分, Count(*) AS 新增客户经理 FROM D201010 WHERE (ID Not In(Select ID From D201009) and 角色1='客户经理') GROUP BY 系统区域划分) AS A ON C.系统区域划分 = A.系统区域划分) LEFT JOIN (SELECT 系统区域划分, Count(*) AS 离职人数 FROM D201009 WHERE ID Not In(Select ID From D201010) GROUP BY 系统区域划分) AS B ON C.系统区域划分 = B.系统区域划分) LEFT JOIN (SELECT 系统区域划分, Count(*) AS 月末客户经理 FROM D201010 WHERE 角色1='客户经理' GROUP BY 系统区域划分) AS D ON C.系统区域划分 = D.系统区域划分) LEFT JOIN (SELECT 系统区域划分, Count(*) AS 月末渠道联系人 FROM D201010 WHERE (角色1 is null) GROUP BY 系统区域划分) AS e ON C.系统区域划分 = e.系统区域划分) LEFT JOIN (SELECT 系统区域划分, Count(*) AS 月末人 FROM D201010 GROUP BY 系统区域划分) AS F ON C.系统区域划分 = F.系统区域划分) LEFT JOIN (SELECT 系统区域划分, Count(*) AS 新增渠道联系人 FROM D201010 WHERE (ID Not In(Select ID From D201009) and 角色1 IS NULL) GROUP BY 系统区域划分) AS G ON C.系统区域划分 = G.系统区域划分) LEFT JOIN (SELECT 系统区域划分, Count(*) AS 修改客户经理 FROM D201010 WHERE (修改日期 Between #9/16/2010# And #10/15/2010# and 角色1 IS not nULL) GROUP BY 系统区域划分) AS H ON C.系统区域划分 = H.系统区域划分) LEFT JOIN (SELECT 系统区域划分, Count(*) AS 修改渠道联系人 FROM D201010 WHERE (修改日期 Between #9/16/2010# And #10/15/2010# and 角色1 IS nULL) GROUP BY 系统区域划分) AS i ON C.系统区域划分 = I.系统区域划分) LEFT JOIN (SELECT 系统区域划分, Count(*) AS 删除客户经理 FROM D201009 WHERE (ID Not In(Select ID From D201010) and 角色1='客户经理') GROUP BY 系统区域划分) AS J ON C.系统区域划分 = J.系统区域划分) LEFT JOIN (SELECT 系统区域划分, Count(*) AS 删除渠道联系人 FROM D201009 WHERE (ID Not In(Select ID From D201010) and 角色1 IS NULL) GROUP BY 系统区域划分) AS K ON C.系统区域划分 = K.系统区域划分) LEFT JOIN (SELECT 系统区域划分, Count(*) AS 经理评级 FROM D201010 WHERE (评级 is not null and 角色1 IS not NULL) GROUP BY 系统区域划分) AS L ON C.系统区域划分 = L.系统区域划分) LEFT JOIN (SELECT 系统区域划分, Count(*) AS 经理未评级 FROM D201010 WHERE (评级 is null and 角色1 IS not NULL) GROUP BY 系统区域划分) AS M ON C.系统区域划分 = M.系统区域划分; |
|