当字符串不等于..然后为空时,我该如何处理大小写



我有一个产品列表,想创建一个语法为:

case when product is not 'apple' or product is not 'pear' or product is not 'plum' then 0 else product end

我该怎么做?我试过

case when product <> 'apple' 
     when product <> 'pear' 
     when product <> 'plum' then 0 
     else product 
end

但这似乎不起作用。

类似的东西?

SELECT  CASE 
            WHEN Product NOT IN ('Apple', 'Pear', 'Plum') THEN 0
            ELSE Product
        END 
FROM ...

我不知道你表中的字段,但它看起来像这个

SELECT case when (Product <> 'apple' 
                  OR Product <> 'pear' 
                  OR Product <> 'plum'
                  ) then 0 else Product end as ProductName
FROM tableName

按照要求执行,使用"OR"而不是"WHEN"分隔条件。

最新更新