开发者

Count only null values in two different columns and show in one select statement

开发者 https://www.devze.com 2023-02-14 20:29 出处:网络
I want to count just the null values in a specific column and all the null values in another specific column, however i want my result to have both of these results shown in one table.

I want to count just the null values in a specific column and all the null values in another specific column, however i want my result to have both of these results shown in one table.

Here is what i have so far:

Select Count(*) as 'Column1Count', Count(*) as 'Column2Count'
   from table1
  开发者_Python百科     Where column1 is null
     and column2 is null

please help


This should work :

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


You could use a case for that:

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

精彩评论

暂无评论...
验证码 换一张
取 消