-1
我不確定是什麼原因導致錯誤。任何幫助將您使用的是像一個HAVING子句WHERE子句可以理解不能在用於GROUP BY子句的GROUP BY列表的表達式中使用聚合或子查詢
SELECT (SUM(DWXP050.Premp))
FROM DWXP050
LEFT JOIN [DWXP050 GL Class]
ON [DWXP050 GL Class].Policy = DWXP050.Policy
AND [DWXP050 GL Class].CDDESC = DWXP050.CDDESC
AND [DWXP050 GL Class].TRDATE = DWXP050.TRDATE
AND [DWXP050 GL Class].[Effective Date] = DWXP050.EFFDTE
AND [DWXP050 GL Class].ASLOB = DWXP050.ASLOB
AND [DWXP050 GL Class].AGENT = DWXP050.AGENT
WHERE (((DWXP050.TRANS) = '10'
OR (DWXP050.TRANS) = '20'))
GROUP BY (SUM(DWXP050.Premp))
HAVING ((([DWXP050 GL Class].AGENT) = '00000BP001')
AND (([DWXP050 GL Class].[Effective Date]) >= '20130201'
AND ([DWXP050 GL Class].[Effective Date]) <= '20130228')
AND (([DWXP050 GL Class].ASLOB) = '170'
OR ([DWXP050 GL Class].ASLOB) = '180')
AND (([DWXP050 GL Class].[Product]) <> 'CUP')
AND (([DWXP050 GL Class].CDDESC) = 'PEST CONTROL SERVICES')
AND (([DWXP050 GL Class].TRDATE) <= '20130401'))
該錯誤非常明顯。你在同一列進行'SUM'和'GROUP'。只要拿出你的'GROUP BY',因爲我懷疑這是不必要的。 – JNK
如果我把它拿出來,我得到這些錯誤:消息8121,級別16,狀態1,行1 列'DWXP050 GL Class.AGENT'在HAVING子句中無效,因爲它不包含在聚合函數或GROUP BY子句。 消息8121,級別16,狀態1,行1 列'DWXP050 GL Class.Effective Date'在HAVING子句中無效,因爲它不包含在聚合函數或GROUP BY子句中。 – user2521438
消息8121,級別16,狀態1,行1 列'DWXP050 GL Class.Effective Date'在HAVING子句中無效,因爲它不包含在聚合函數或GROUP BY子句中。 消息8121,級別16,狀態1,行1 列'DWXP050 GL Class.ASLOB'在HAVING子句中無效,因爲它不包含在聚合函數或GROUP BY子句中。 消息8121,級別16,狀態1,行1 列'DWXP050 GL Class.ASLOB'在HAVING子句中無效,因爲它不包含在聚合函數或GROUP BY子句中。 – user2521438