cuốn sách gpt4 ai đã làm

MySQL LIKE 和 NOT LIKE 缺少一条记录

In lại Tác giả: Hồ Xil 更新时间:2023-11-01 08:19:54 26 4
mua khóa gpt4 Nike

我有一个名为 platform 的表,其中有一列名为 entityid。 entityid 中的数据应该遵循 n.n.n 格式(其中 n = 1 个或多个数字,第一个数字是站点 ID)。

如果我运行这个查询:

SELECT count(*) FROM platform

我得到:16063所以我的表中有 16063 行。当我尝试仅过滤站点 18 时,我运行此查询:

SELECT count(*) FROM platform
where entityid like '18.%.%'

我得到:4454到目前为止,一切都很好。但是如果我试图找到不在站点 18 的平台:

SELECT count(*) FROM platform
where entityid not like '18.%.%'

我得到:11608问题来了:4454 + 11608 = 16062
我缺少记录。我想我得到了站点 18 的所有平台,然后是站点 18 以外的所有平台 - 我怎么会遗漏一条记录?

câu trả lời hay nhất

问题可能是空值。试试这个,看看它是否返回一条记录:

select *
from platform
where entityid is null;

NULL 值几乎使所有比较都失败(is null 除外)。

关于MySQL LIKE 和 NOT LIKE 缺少一条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16721701/

26 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress