gpt4 book ai didi

MySQL如何查找表中的空数据

转载 作者:行者123 更新时间:2023-11-29 04:32:38 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com