MySQL如何查找表中的空数据

标签 mysql sql null

场景:我有一个包含重复数据的表。该表的其中一列是 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 表中获取 ddateNULL 的金额。

(2)

select * from instrument_nt where `ddate` IS NULL;

你会得到一个ddate为NULL的结果集;

关于MySQL如何查找表中的空数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55653728/

相关文章:

mysql - 使用 Union All 获取总计

MySQL WHERE 子句中整数的第一个数字

mysql - 按某种顺序排序,然后随机?

c++ - boost::any 如何检查空值/未定义值

java - 返回 Null、异常、契约

mysql - 基于文件访问mysql数据库

mysql - 使用 MySQL 查询检索所有 'Child' 项目

SQL表将一个id的多行分成多列

sql - 与 CLOB 一起使用的类似 UTL_MATCH 的函数

mysql检查值是否为空