EDIT:この回答は、MySQLためである(最初は慎重に読んでいない)
this answerから、私はこれを考えますその結果、あなたのすべての「ヌル」セルをカウントします:
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 [email protected] and [email protected];
-- 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 [email protected] and [email protected];
-- 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;
可能な複製[テーブル内のすべてのNULL値をカウントする方法?](http://stackoverflow.com/questions/2295318/how-to-count-all -null-values-in-a-table) – webmaster
@webmaster、あなたの可能な複製*は 'SQLサーバー 'に対して実行されている間に' MySQL'用です – Shnugo
ありがとう、ありがとうございます。 – webmaster