我无法从以下查询中获得所需的结果。请给我一点帮助吗?谢谢。
$sql = "SELECT id,
CASE
when Rcon = '' then '0',
when Rcon = 'x' then '1',
when Rcon = '2x' then '2',
when Rcon = 'x3' then '2',
when Rcon = 'x,x3' then '3',
when Rcon = 'x4' then '3'
ELSE Rcon END AS Rcon
FROM mytable";
最佳答案
您的CASE
语句有问题。
SELECT id,
CASE
when Rcon = '' then '0'
when Rcon = 'x' then '1'
when Rcon = '2x' then '2'
when Rcon = 'x3' then '2'
when Rcon = 'x,x3' then '3'
when Rcon = 'x4' then '3'
ELSE Rcon
END AS Rcon
FROM mytable;
请注意,我已经从
,
语句的每一行的末尾删除了逗号(CASE
)。逗号在个案陈述中无效。关于mysql - mysql查询中的CASE函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54480925/