Michael Fischer Michael Fischer - 6 months ago 9
SQL Question

Count NULL Values from multiple columns with SQL

I have 3 columns let say a, b, and c. I need to count the NULL values in each column.

For example:

A | B | C
-------------
1 |Null| 1
1 | 1 | Null
NULL| 1 | 1
NULL|NULL| 1


Should output:

A | B | C
---------------
2 | 2 | 1


I've tried count, sum, sub-queries but nothing has worked for me yet. Any input would be appreciated!

Answer
SELECT COUNT(*)-COUNT(A) As A, COUNT(*)-COUNT(B) As B, COUNT(*)-COUNT(C) As C
FROM YourTable;