我有一个表employee,其中有一个公司列,其中包含所有空值
现在,我想使用一个NOT IN运营商作为公司名称
select * from employee where employee.company NOT IN ('ABC', 'DEF')
现在从技术上讲,这不应该改变结果,因为公司列已经有空值。
但是添加NOT IN0 行。
这是因为employee.company列有NULL值吗?
试试这个方法:
select *
from employee E
where (E.company NOT IN ('ABC', 'DEF')
or E.company is null)
SQL 使用三个值逻辑:true、false和unknown。null与结果进行比较,结果unknown并非如此true。
所以where像这样的子句:
where null in (1,2)
不会返回任何行。