SQL 服务器全部(select ...)为空
SQL Server all(select ...) is null
我搜索过,但找不到任何相关信息。我需要 SQL 服务器查询,例如
select t1.x
from @tablename as t1
where all
(select t2.y from @tablename as t2 where t1.x=t2.x) is null
@tablename
相同
但我无法使用 all(select ...) is null
部分查询。
谢谢。
你要not exists
吗?
select t1.x
from @tablename as t1
where not exists (select t2.y from @tablename as t2 where t1.x = t2.x)
这测试没有匹配值。
或者,也许,
select t1.x
from @tablename t1
where not exists (select 1
from @tablename as t2
where t1.x = t2.x and t2.y is not null
) ;
这测试任何匹配值都具有 NULL
for y
。
我搜索过,但找不到任何相关信息。我需要 SQL 服务器查询,例如
select t1.x
from @tablename as t1
where all
(select t2.y from @tablename as t2 where t1.x=t2.x) is null
@tablename
相同
但我无法使用 all(select ...) is null
部分查询。
谢谢。
你要not exists
吗?
select t1.x
from @tablename as t1
where not exists (select t2.y from @tablename as t2 where t1.x = t2.x)
这测试没有匹配值。
或者,也许,
select t1.x
from @tablename t1
where not exists (select 1
from @tablename as t2
where t1.x = t2.x and t2.y is not null
) ;
这测试任何匹配值都具有 NULL
for y
。