Skip to content Skip to sidebar Skip to footer

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.



Post a Comment for "COUNT CASE And WHEN Statement In MySQL"