首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么在MySQL中对列为空的行使用NOT LIKE for one column筛选结果?

为什么在MySQL中对列为空的行使用NOT LIKE for one column筛选结果?
EN

Stack Overflow用户
提问于 2012-12-20 16:17:45
回答 2查看 300关注 0票数 2

当我使用这个查询时:

代码语言:javascript
复制
SELECT `visitors`.`id`, `visitors`.`ip`, `visitors`.`url`, `visitors`.`time`, `visitors`.`agent`, `visitors`.`reference`
FROM (`visitors`)
WHERE  `reference` NOT LIKE '%bot%'
ORDER BY `id` desc
LIMIT 2000

在结果中,我看不到reference列为空的行。如何创建引用列为空的结果集?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-12-20 16:18:48

尝试:

代码语言:javascript
复制
SELECT `visitors`.`id`, `visitors`.`ip`, `visitors`.`url`, `visitors`.`time`, `visitors`.`agent`, `visitors`.`reference`
FROM (`visitors`)
WHERE  `reference` NOT LIKE '%bot%' OR `reference` IS NULL
ORDER BY `id` desc
LIMIT 2000

处理NULL的方式与处理空值的方式不同。

票数 6
EN

Stack Overflow用户

发布于 2012-12-21 19:54:33

尝试添加显式条件以获取为null的列。

代码语言:javascript
复制
select visitors.id, visitors.ip, visitors.url, visitors.time, visitors.agent, visitors.reference
from visitors
where reference not like '%bot%' or reference is null
order by id desc
limit 2000;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13967844

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档