场景:我有一个包含重复数据的表。该表的其中一列是 ddate,如果它为空/空,我想选择该行(并将其删除)。但由于某种原因,我无法通过直接查询找到空行。
问题:当我运行以下查询 (1) 时:
select
`ddate`,
count(1) as `nb`
from instrument_nt
group by `ddate`;
我得到了 ddate 为 NULL 以及它有其他值的行数。但是当我运行查询 (2) 时:
select count(*) from instrument_nt where `ddate` = Null;
或
select * from instrument_nt where `ddate` = NULL;
我的查询结果不是 0 就是空。
问题:这两个查询(1 和 2)有什么区别?如何正确删除日期为空/缺失的数据?
最佳答案
NULL
mean unknow it's a value.
如果你想获得 NULL
行你需要使用 IS NULL
而不是 eqaul NULL
select count(*) from instrument_nt where `ddate` IS Null;
What is the difference between those two queries (1 and 2)? How can I properly delete the data that has null/missing dates?
(1)
select count(*) from instrument_nt where `ddate` IS Null;
您将从 instrument_nt
表中获取 ddate
为 NULL
的金额。
(2)
select * from instrument_nt where `ddate` IS NULL;
你会得到一个ddate
为NULL的结果集;
关于MySQL如何查找表中的空数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55653728/