我创建了一个带有枚举列的表,如下所示
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?
对于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)
| 归档时间: |
|
| 查看次数: |
3656 次 |
| 最近记录: |