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!
Advertisement
Answer
SELECT COUNT(*)-COUNT(A) As A, COUNT(*)-COUNT(B) As B, COUNT(*)-COUNT(C) As C FROM YourTable;