如果一个人都标记为 1,我怎样才能让我的案例陈述 return 在我的自定义偏好列中既喜欢​​动作又喜欢喜剧

how can i get my case statement to return both prefer action and prefer comedy in my custom preference column if a person has both marked as 1

SELECT FirstName, LastName,

CASE 

WHEN [Action] = '1' THEN 'Prefer Action'

WHEN Comedy = '1' THEN 'Prefer Comedy'

WHEN Drama = '1' THEN 'Prefer Drama'

WHEN Horror = '1' THEN 'Prefer Horror'

WHEN Romance = '1' THEN 'Prefer Romance'
ELSE ' '
END AS 'Customer Preference'

FROM RentalMDB.dbo.Customers

您可以使用下面的 Union 语句,

SELECT FirstName, LastName,
CASE 
WHEN [Action] = '1' THEN 'Prefer Action'
WHEN Drama = '1' THEN 'Prefer Drama'
WHEN Horror = '1' THEN 'Prefer Horror'
WHEN Romance = '1' THEN 'Prefer Romance'
ELSE ' '
END AS 'Customer Preference'
FROM RentalMDB.dbo.Customers

UNION ALL

SELECT FirstName, LastName,
CASE 
WHEN Comedy = '1' THEN 'Prefer Comedy'
WHEN Drama = '1' THEN 'Prefer Drama'
WHEN Horror = '1' THEN 'Prefer Horror'
WHEN Romance = '1' THEN 'Prefer Romance'
ELSE ' '
END AS 'Customer Preference'
FROM RentalMDB.dbo.Customers