Skip to content
Advertisement

Count not null in sql

I have a table A with column data:

mdr1222
-------
pprgd24
-------
invalid
-------
invalid
abc2345

I want to get a count of the invalid and blank(—). I tried :

SELECT count(data)
from A
where data = 'invalid' and  null

but it doesn’t work. Can someone please help me figure out what I am doing wrong here?

Advertisement

Answer

This should work as well.

SUM(CASE WHEN data IS NULL OR data = 'Invalid' THEN 1 ELSE 0 END)
FROM A
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement