SQL Server all(select ...)为null

时间:2015-07-30 11:26:38

标签: mysql sql sql-server isnull

我搜索但我找不到任何关于它的信息。我需要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部分查询。

感谢。

1 个答案:

答案 0 :(得分:1)

您想要update TableName set enddate = dateadd(day,1,startdate) 吗?

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