MYSQL 在枚举上“不等于”

Raj*_*esh 2 mysql enums

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

create table test_1(
    id BIGINT NOT NULL AUTO_INCREMENT,
    order_billing_status ENUM ("BILLING_IN_PROGRESS") DEFAULT NULL
);
Run Code Online (Sandbox Code Playgroud)

我插入两个值如下

+-----+----------------------+
| id  | order_billing_status |
+-----+----------------------+
| 100 | NULL                 |
| 200 | BILLING_IN_PROGRESS  |
+-----+----------------------+
Run Code Online (Sandbox Code Playgroud)

现在,当我尝试查询 like 时select * from test_1 where order_billing_status <> "BILLING_IN_PROGRESS";,它​​返回空结果,而不是返回以下结果。

+-----+----------------------+
| id  | order_billing_status |
+-----+----------------------+
| 100 | NULL                 |
+-----+----------------------+
Run Code Online (Sandbox Code Playgroud)

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

Mit*_*tel 8

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

=<>忽略NULL

select * from  test_1 
where order_billing_status <> "BILLING_IN_PROGRESS"  OR order_billing_status IS NULL
Run Code Online (Sandbox Code Playgroud)

  • 不,它适用于所有数据类型...对于 string、int 以及当我们需要比较 NULL 时,我们必须使用“IS NULL”或“IS NOT NULL” (2认同)