Sql 选择组中所有值均为空的行

Sql 选择组中所有值均为空的行,sql,sqlite,Sql,Sqlite,如何: 选择组中所有行均为NULL的行。下面的组由id定义。我 希望选择所有值均为NULL的行 Id Var1 1 NULL 1 NULL 1 NULL 2 10 2 20 2 30 3 NULL 3 30 我所尝试的: select id from table where all var1 is null group by id 预期结果: id var1 1 NULL 1 NULL 1 NULL 使用having代替where。它在聚合后进行

如何: 选择组中所有行均为
NULL
的行。下面的组由
id
定义。我 希望选择所有值均为
NULL
的行

Id Var1
1  NULL
1  NULL    
1  NULL  
2  10
2  20
2  30
3  NULL
3  30
我所尝试的:

select id
from table 
where all var1 is null
group by id
预期结果:

id var1
1  NULL
1  NULL    
1  NULL

使用
having
代替
where
。它在聚合后进行过滤:

select id
from table 
group by id
having max(var1) is null;
类似的方法使用:

having count(var1) = 0

您可以尝试使用此查询:

select id,Var1
from table1 as a
where not exists (select id
                  from table1 as b
                  where a.id=b.id and b.Var1 is not null)
子查询获取的id值不为null,因此您无法在主查询中获取它们