I have the following case statement, but I am not getting the desired results. I would like the results to return a single row for each fname, lname, email with 'Y' or 'N' values for the WEBCAST_1...4.
Right now I get multiple rows where fname, lname, email has different value for WEBCAST_1, 2, 3 and 4.
How can I group it so one row will show wether fname, lname, email attended more than one WEBCAST?
SELECT distinct fname, lname, email,
(CASE when web_cast_id = 1 then 'Y' else 'N' end) WEBCAST_1,
(CASE when web_cast_id = 2 then 'Y' else 'N' end) WEBCAST_2,
(CASE when web_cast_id = 3 then 'Y' else 'N' end) WEBCAST_3,
(CASE when web_cast_id = 4 then 'Y' else 'N' end) WEBCAST_4
SELECT
fname,
lname,
email,
CASE WHEN SUM(CASE WHEN web_cast_id = 1 THEN 1 END) = 0 THEN 'N' ELSE 'Y' END WEBCAST_1,
CASE WHEN SUM(CASE WHEN web_cast_id = 2 THEN 1 END) = 0 THEN 'N' ELSE 'Y' END WEBCAST_2,
CASE WHEN SUM(CASE WHEN web_cast_id = 3 THEN 1 END) = 0 THEN 'N' ELSE 'Y' END WEBCAST_3,
CASE WHEN SUM(CASE WHEN web_cast_id = 4 THEN 1 END) = 0 THEN 'N' ELSE 'Y' END WEBCAST_4
FROM
marketing_leads.web_cast
GROUP BY
fname,
lname,
email
Bookmarks