2011-03-05 11 views
3

我想只计算特定列中的空值和另一个 特定列中的所有空值,但是我希望我的结果具有这两个结果显示在一张表中。只计算两个不同列中的空值并显示在一条select语句中

这里是我到目前为止有:

Select Count(*) as 'Column1Count', Count(*) as 'Column2Count' 
    from table1 
     Where column1 is null 
    and column2 is null 

请帮助

回答

4

这应该工作:

select 
    (select count(*) from table1 where column1 is null) as 'Column1Count', 
    (select count(*) from table1 where column2 is null) as 'Column2Count'; 
+0

这工作完美。谢谢 – Warz 2011-03-05 18:01:37

1

你可以使用一个案例:

select sum(case when Column1 is null then 1 end) as Col1Count 
,  sum(case when Column2 is null then 1 end) as Col2Count 
from table1 
+0

谢谢,在这个查询中,我从来没有使用的情况下,但这给了我正确的输出 – Warz 2011-03-05 18:02:31

相关问题