MySQL counts all NULL columns

I need to count and return the number of NULL columns in my MySQL query.

SELECT * from posttracks WHERE trackid=100000; 

How would I COUNT all NULL columns?

Edit: to be clear, I don't need the number of rows with null values, I need the number of columns in a row with NULL values.

+6
source share
5 answers
 SELECT count(*) from posttracks WHERE Col1 is NULL 
+5
source

If I understand your question correctly:

 SELECT ISNULL(col1) + ISNULL(col2) + ... + ISNULL(col16) AS cnt FROM yourTable WHERE trackid=100000 
+5
source

I assume that you are trying to find all rows that have at least one iS NULL column.

Let's say you have three columns - col1, col2, col3 in the table - table1. then you can write a query like

SELECT COUNT (*) FROM table1 WHERE col1 IS NULL OR col2 IS NULL OR col3 IS NULL.

If you have more columns, join them using OR

+1
source
 SELECT count(*) as amount FROM posttracks WHERE trackid IS NULL GROUP BY trackid; 
0
source

select count(*) from posttrack where trackid is null;

Edit: duplicate previous answer

0
source

Source: https://habr.com/ru/post/899022/


All Articles