SELECT CONCAT(firstname," ",lastname," ",CASE dept_id
WHEN '1' THEN 'ITD'
WHEN '4' THEN 'FMAD'
WHEN '6' THEN 'GCSMD'
WHEN '7' THEN 'SSHED'
WHEN '10' THEN 'GPD'
ELSE 'Z_ISDC'
END AS ayam) as staffname
FROM ost_staff
我想要staffname
的输出是“John Doe ITD”但是
它不起作用。
答案 0 :(得分:6)
试试这个,您的CASE
格式不正确。
SELECT
CONCAT(firstname," ",lastname," ",
CASE WHEN dept_id = '1' THEN 'ITD'
WHEN dept_id = '4' THEN 'FMAD'
WHEN dept_id = '6' THEN 'GCSMD'
WHEN dept_id = '7' THEN 'SSHED'
WHEN dept_id = '10' THEN 'GPD' ELSE 'Z_ISDC' END)
as staffname
FROM ost_staff
此外,您无法命名CASE
,END
需要一个简单的CASE
。
答案 1 :(得分:0)
从AS ayam
的{{1}}删除CASE
。
当您使用END
子句的结果作为CASE
的参数时,您不能使用别名。