我有以下查詢,您可以看到多個Count(CompetitorID)
調用。這是一個性能問題,還是SQL Server 2008'緩存'Count
?如果這是性能問題,是否可以存儲Count
以防止多次查找?在SELECT查詢中防止重複COUNT
SELECT EventID,Count(CompetitorID) AS NumberRunners,
CASE WHEN Count(CompetitorID)<5 THEN 1
WHEN Count(CompetitorID)>=5 AND Count(CompetitorID)<=7 THEN 2
ELSE 3 END AS NumberPlacings
FROM Comps
GROUP BY EventID Order By EventID;
雖然語法看起來像是在重複某個操作,但查詢分析器可能會優化它。 – HABO 2012-03-08 02:26:02