下面的 SQL 抛出错误 8120,它说:
列 'webgroup_message2_archive.opened' 在选择列表中无效,因为它不包含在聚合函数或 GROUP BY 子句中
即使我没有使用违规列作为SELECT
子句的一部分。当我更改子查询时
SELECT webgroup_message2_testTable.message_id
到(111,222,...等)之类的列表`它有效!那么问题来自与聚合函数不兼容的子查询?我还确保子查询的数据类型与测试表达式匹配。
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