首页 > 解决方案 > 如何在 MySQL 服务器的“where”中使用案例

问题描述

我收到一个错误,

表达式在 case 内的条件下无效。

运行 MySQL 时:

WHERE
    CASE
        WHEN TBL1.Reissued<>'1'
            THEN
                fare IS NOT NULL
                AND 
                fare <> 0.00
    END

WHERE
    fare IS NOT NULL
    AND 
    fare <> 0.00

标签: mysqlsql

解决方案


首先,fare IS NOT NULL AND fare <> 0.00可以简化为fare <> 0.00,因为任何条件都会消除NULL,因为每个与NULLvalue 的比较unknown都会被认为是错误的。

现在,您可以使用这样的条件:

where (TBL1.Reissued<>'1' and fare <> 0.00) or TBL1.Reissued='1'

推荐阅读