EDIT: this answer is for MySQL (didn't read at first)
From this answer , I think this result will count your all โnullโ cells:
SET @db = 'your_database_name'; -- database SET @tb = 'your_table_name'; -- table SET @x = ''; -- will hold the column names with ASCII method applied to retrieve the number of the first char SET @numcolumns = 0; -- will hold the number of columns in the table -- figure out how many columns we have SELECT count(*) into @numcolumns FROM information_schema.columns where table_name=@tb and table_schema=@db ; -- we have to prepare some query from all columns of the table SELECT group_concat(CONCAT('ASCII(',column_name,')')) into @x from information_schema.columns where table_name=@tb and table_schema=@db ; -- after this query we have a variable separated with comma like -- ASCII(col1),ASCII(col2),ASCII(col3) -- we now generate a query to concat the columns using comma as separator (null values are omitted from concat) -- then figgure out how many times the comma is in that substring (this is done by using length(value)-length(replace(value,',','')) -- the number returned is how many non null columns we have in that column -- then we deduct the number from the known number of columns, calculated previously -- the +1 is added because there is no comma for single value SET @s = CONCAT('SELECT @numcolumns - (length(CONCAT_WS(\',\',', @x, '))-length(replace(CONCAT_WS(\',\',', @x, '),\',\',\'\')) + 1) FROM ',@db,'.',@tb,';'); PREPARE stmt FROM @s; EXECUTE stmt; -- after this execution we have returned for each row the number of null columns -- I will leave to you to add a sum() group call if you want to find the null values for the whole table DEALLOCATE PREPARE stmt;
source share