在下面的SQL語句中,我應該使用DISTINCT,因爲我在Where Where子句中有一個Group By?思考?使用不同還是不是
SELECT [OrderUser].OrderUserId, ISNULL(SUM(total.FileSize), 0), ISNULL(SUM(total.CompressedFileSize), 0)
FROM
(
SELECT DISTINCT ProductSize.OrderUserId, ProductSize.FileInfoId,
CAST(ProductSize.FileSize AS BIGINT) AS FileSize,
CAST(ProductSize.CompressedFileSize AS BIGINT) AS CompressedFileSize
FROM ProductSize WITH (NOLOCK)
INNER JOIN [Version] ON ProductSize.VersionId = [Version].VersionId
) AS total RIGHT OUTER JOIN [OrderUser] WITH (NOLOCK) ON total.OrderUserId = [OrderUser].OrderUserId
WHERE NOT ([OrderUser].isCustomer = 1 AND [OrderUser].isEndOrderUser = 0 OR [OrderUser].isLocation = 1)
AND [OrderUser].OrderUserId = 1
GROUP BY [OrderUser].OrderUserId
取決於您之後的結果集。你在做什麼? – 2010-06-04 14:08:13
類型的脫離主題,但是必須加入版本JOIN?你似乎沒有在任何地方使用它。是否有版本中不存在的ProductSize.VersionId?如果不是的話,你可能會帶來多個結果,因爲只有連接才能完全不必要地使用DISTINCT再次刪除它們。 – 2010-06-04 14:33:53
當你刪除DISTINCT時,你會得到不同的結果嗎? – HLGEM 2010-06-04 15:00:55