Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Count not null in sql

Tags:

sql

mysql

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?

like image 747
facebook-10153603764680056 Avatar asked Sep 26 '22 06:09

facebook-10153603764680056


1 Answers

This should work as well.

SUM(CASE WHEN data IS NULL OR data = 'Invalid' THEN 1 ELSE 0 END)
FROM A
like image 173
Langosta Avatar answered Sep 27 '22 23:09

Langosta