The following SQL throws error 8120, which says:
Column 'webgroup_message2_archive.opened' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause
Even though I am not using the offending column as part of the SELECT clause. When I change the subquery
SELECT webgroup_message2_testTable.message_id
to a list like (111,222,...etc)` it works! So the problem comes from the subquery not compatible with aggregated function? I also made sure the data types of subquery match the test expression.
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.openedis a part of the select list..