代码之家  ›  专栏  ›  技术社区  ›  Rajesh

枚举上的MYSQL“不等于”

  •  1
  • Rajesh  · 技术社区  · 7 年前

    我创建了一个带有枚举列的表,如下所示

    create table test_1(
        id BIGINT NOT NULL AUTO_INCREMENT,
        order_billing_status ENUM ("BILLING_IN_PROGRESS") DEFAULT NULL
    );
    

    我插入两个值,如下所示

    +-----+----------------------+
    | id  | order_billing_status |
    +-----+----------------------+
    | 100 | NULL                 |
    | 200 | BILLING_IN_PROGRESS  |
    +-----+----------------------+
    

    现在当我试着询问 select * from test_1 where order_billing_status <> "BILLING_IN_PROGRESS"; ,它将返回空结果,而不是返回以下结果。

    +-----+----------------------+
    | id  | order_billing_status |
    +-----+----------------------+
    | 100 | NULL                 |
    +-----+----------------------+
    

    这是mysql中的错误还是我做错了什么?如果是bug,是否有解决方法,或者我应该使用varchar而不是enum?

    4 回复  |  直到 7 年前
        1
  •  6
  •   Mittal Patel    7 年前

    对于 NULL 值检查我们需要使用 IS NULL IS NOT NULL

    = <> 忽略 无效的

    select * from  test_1 
    where order_billing_status <> "BILLING_IN_PROGRESS"  OR order_billing_status IS NULL
    
        2
  •  1
  •   cdaiga    7 年前

    请尝试以下操作:

    select * from  test_1 
    where order_billing_status<>'BILLING_IN_PROGRESS'
    or order_billing_status is null; 
    
        3
  •  0
  •   stackFan    7 年前

    问题是 <> 忽略 null . 只需使用以下关键字 is not null is null 检查空值。

        4
  •  0
  •   Robert Columbia yusuf dalal    7 年前

    尝试以下操作:

    select * from  test_1 where order_billing_status != "BILLING_IN_PROGRESS";