日期:2014-05-18  浏览次数:20376 次

帮忙优化一下这段SQL
执行完毕需要30秒,哪位高人帮忙优化一下?

SELECT a.DeptWBS,a.DeptName,
ISNULL(b.GCXXDJ,0) AS GCXXDJ,ISNULL(c.ZTBXMS,0) AS ZTBXMS
FROM T_E_Sys_Department a
LEFT JOIN
(
SELECT dbo.GetCompanyID(aa.C_BizRangeID) C_BizRangeID,bb.ZTBXMS
FROM T_P_Bid_gcxxdj aa
INNER JOIN
(
SELECT COUNT(1) AS ZTBXMS,dbo.GetCompanyID(C_BizRangeID) C_BizRangeID
FROM T_P_Bid_zbwjps aa
GROUP by C_BizRangeID
)bb
ON bb.C_BizRangeID=aa.C_BizRangeID
WHERE aa.Post='是' AND aa.Moderate='是'
GROUP BY aa.C_BizRangeID,bb.ZTBXMS
)c
ON c.C_BizRangeID=a.DeptID
WHERE a.DeptName IS NOT NULL AND a.DeptName<>'' AND (a.TypeID='1' or a.TypeID='10')
ORDER BY a.DeptWBS

------解决方案--------------------
SQL code

WHERE a.DeptName IS NOT NULL AND a.DeptName <>'' AND (a.TypeID='1' or a.TypeID='10')