[英]SQL selecting values with Null and 0 values from range null, 0 & 1
T-SQL查询返回的列之一具有这三个值中的一个
NULL, 0, 1
我试图过滤掉1个值,但是当我使用这些子句时:
查询:
select foo
from dbo.table1
where ..
条款:
where foo <> 1
:仅返回列中具有0值的数据 Where foo is null
:仅返回列中的空值 where foo in (Null, 0)
:仅返回列中具有0值的数据 过滤数据的正确方法是什么?
在SQL Server中,您可以执行以下操作:
where foo <> 1 or foo is null
或者,如果您知道实际上只有三个值,例如:
where coalesce(foo, -1) <> 1
SQL Server没有NULL
-safe比较。 标准SQL支持:
where foo is distinct from 1
但这在SQL Server中不可用。
由于只有3个值,这就足够了:
where isnull(foo, 0) <> 1
要么:
where isnull(foo, 0) = 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.