的我有以下查詢:SQL INSERT INTO SELECT語句無效使用組功能
INSERT INTO StatisticalConsultationAgreement VALUES (
queryType, entityCode, entityType, queryClass,queryTables,period,
COUNT(queryClass), SUM(numberRecords), SUM(recordsFound),
SUM(NorecordsFound), NOW(), 'system');
SELECT
MONTH(EndDateTimeProcessing),YEAR(EndDateTimeProcessing),
entityType,
entityCode,
queryType,
queryClass,
EndDateTimeProcessing as period
FROM agreementFile
WHERE
MONTH(EndDateTimeProcessing)=MONTH(DATE_SUB(CURDATE(), INTERVAL 1 MONTH))
AND YEAR(EndDateTimeProcessing)=YEAR(CURDATE())
GROUP BY entityType,entitycode,queryType, queryClass;
當我運行查詢,我得到下一個錯誤:
Error code 1111, SQL state HY000: Invalid use of group function
Line 1, column 1
Executed successfully in 0,002 s.
Line 5, column 2
爲什麼ocurre呢?
如何解決?
你能解釋一下你用這段代碼做什麼?有兩個語句,一個帶有錯誤的INSERT命令(聚合函數SUM和COUNT不能在此上下文中使用)和另一個SELECT語句。 – krokodilko