Read only zero values ​​in two different columns and show select in one clause

I want to count only the null values ​​in a certain column and all the null values ​​in another, but I want my result to have both of these results shown in the same table.

Here is what I still have:

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

please, help

+3
source share
2 answers

This should work:

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

You can use the case for this:

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
+1
source

Source: https://habr.com/ru/post/1796523/


All Articles