我有一個查詢在SQL Server中保持超時。查詢中最大的表格只有幾百行。基本上我試圖將一堆表中的數據與tblNovaPosts中的novaPost字段進行匹配以創建報告。我應該如何更改此查詢以使其運行速度更快?使用多個連接優化此查詢
SELECT TOP (100) PERCENT tblNovaPosts.type, tblNovaPosts.novaPost,
ISNULL(SUM(tblAuditTrail.amount), 0) AS FUNDING,
ISNULL(SUM(tbl510.allot), 0) AS ALLOT,
ISNULL(SUM(tblStanfin.oblig), 0)
+ ISNULL(SUM(tblSof.obligationsCum), 0)
+ ISNULL(SUM(tblSpecAppt.obligations), 0)
+ ISNULL(SUM(tblJlens.obligationsCum), 0)
- ISNULL(SUM(viewReimbObs.reimbObs), 0) AS OBLIGATED,
ISNULL(SUM(tblSof.commitmentsNonCum), 0)
+ ISNULL(SUM(tblRmt.commitment),0)
+ ISNULL(SUM(tblReimb.commitmentsNonCum), 0)
- ISNULL(SUM(viewReimbObs.reimbObs), 0) AS DIRCOMMIT
FROM tblNovaPosts LEFT OUTER JOIN
tblAuditTrail ON tblNovaPosts.novaPost = tblAuditTrail.novaPost LEFT OUTER JOIN
tbl510 ON tblNovaPosts.novaPost = tbl510.novaPost LEFT OUTER JOIN
tblStanfin ON tblNovaPosts.novaPost = tblStanfin.novaPost LEFT OUTER JOIN
tblSof ON tblNovaPosts.novaPost = tblSof.novaPost LEFT OUTER JOIN
tblSpecAppt ON tblNovaPosts.novaPost = tblSpecAppt.novaPost LEFT OUTER JOIN
tblJlens ON tblNovaPosts.novaPost = tblJlens.novaPost LEFT OUTER JOIN
viewReimbObs ON tblNovaPosts.novaPost = viewReimbObs.novaPost1 LEFT OUTER JOIN
tblRmt on tblNovaPosts.novaPost = tblRmt.novaPost LEFT OUTER JOIN
tblReimb ON tblNovaPosts.novaPost = tblReimb.novaPost
GROUP BY tblNovaPosts.type, tblNovaPosts.novaPost
ORDER BY tblNovaPosts.type, tblNovaPosts.novaPost
'TOP(100)PERCENT'沒有任何意義.. – Magnus
我在視圖中看到它,當我想通過 –
@Conrad強制執行默認命令時 - [自SQL Server 2000以來, (http://blogs.msdn.com/b/queryoptteam/archive/2006/03/24/560396.aspx) –