MySQL中的case语句是否可以匹配多个值?

3

考虑以下示例:

case when type = 'myValue' then 'default' else type end

如何在这里列出几个值 type='myValue'?而不是重复:
case
     when type = 'myValue' then 'default'
     when type = 'other' then 'default'
     else type
end
1个回答

2

您可以在when子句中使用任何条件。例如,在您的情况下,您可以使用in运算符:

case
     when type in ('myValue','other') then 'default'
     else type
end

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接