下面的SQL拋出錯誤8120,它說:Microsoft SQL Server錯誤
列「webgroup_message2_archive.opened」,因爲它不是在聚合函數或GROUP BY子句包含在選擇列表中無效
即使我沒有使用違規列作爲SELECT
子句的一部分。當我將子查詢
SELECT webgroup_message2_testTable.message_id
更改爲類似(111,222,...等)的列表`It works!所以問題來自與查詢集合函數不兼容的子查詢?我還確保子查詢的數據類型與測試表達式匹配。
SELECT
CASE
WHEN arch.opened = '1'
THEN(CASE
WHEN (message_id IN (SELECT webgroup_message2_testTable.message_id
FROM webgroup_message2_testTable))
THEN 'Clicked' ELSE 'Opened' END)
ELSE 'No activity/response'
END AS status, count(1)
FROM webgroup_message2_archive AS arch
INNER JOIN webgroup_development AS dev
ON dev.development_id = arch.HTMLID
WHERE dev.email_tracker_code = 'A4725'
GROUP BY
CASE
WHEN arch.opened= '1'
THEN(CASE
WHEN (message_id IN (SELECT webgroup_message2_testTable.message_id
FROM webgroup_message2_testTable))
THEN 'Clicked' ELSE 'Opened' END)
ELSE 'No activity/response'
END
'CASE WHEN arch.opened'是選擇列表的一部分.. – Blorgbeard
嘗試在計數上放一些值.. say - > count(dev.development_id) – maSTAShuFu