2

当我使用这个查询时:

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列为空的行。我应该怎么做才能创建一个包含空参考列的结果集?

4

2 回答 2

6

尝试 :

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与空值的处理方式不同。

于 2012-12-20T08:18:48.050 回答
0

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

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;
于 2012-12-21T11:54:33.370 回答