SELECT DISTINCT AppID,
CASE
WHEN Category = '< 18 years old' THEN 'yes'
ELSE ''
END AS '<18years old',
CASE
WHEN Category = 'SSN Exists' THEN 'yes'
ELSE ''
END AS 'Applicant has SSN',
CASE
WHEN Category = 'Self Employed' THEN 'yes'
ELSE ''
END AS 'Self employed'
FROM Table1
WHERE AppID = 123
期望的输出 我正在尝试生成下面的结果,其中每个 AppID 只有 1 行,其中包含与其相关的所有信息。上面的代码为每个应用程序生成多行。我试图将 case 语句与 1 END 放在一起,但是当我在 END 关键字之前使用 Aliases 时出现错误。谢谢
AppID <18 Year old Applicant has SSN Self employed
123 yes yes
124 yes yes
125 yes yes