COUNT CASE And WHEN Statement In MySQL


Answer :

Use:



SELECT SUM(CASE 
WHEN t.your_column IS NULL THEN 1
ELSE 0
END) AS numNull,
SUM(CASE
WHEN t.your_column IS NOT NULL THEN 1
ELSE 0
END) AS numNotNull
FROM YOUR_TABLE t


That will sum up the column NULL & not NULL for the entire table. It's likely you need a GROUP BY clause, depending on needs.



Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable