3
我知道這個問題已經被問了很多,但是當我解決了錯誤信息,並使用HAVING子句,我還是接受了可怕的:TSQL - 聚集在HAVING子句
An aggregate may not appear in the WHERE clause unless it is in a
subquery contained in a HAVING clause or a select list,
and the column being aggregated is an outer reference.
我在做什麼錯了,在這裏?
SELECT
mr.ClubKeyNumber,
COUNT(mr.MonthlyReportID),
SUM(CONVERT(int,mr.Submitted))
FROM MonthlyReport mr
WHERE mr.ReportYear = 2014
AND COUNT(mr.MonthlyReportID) = 12
GROUP BY mr.ClubKeyNumber
HAVING (SUM(CONVERT(int,mr.Submitted))) > 11
您可能希望將此謂詞COUNT(mr.MonthlyReportID)= 12'移至「HAVING」子句。 –
'AND COUNT(mr.MonthlyReportID)= 12'將其添加到條款 –