2014-01-16 38 views
-1

有沒有什麼方法可以找到MySql表中所有值的總計數。我能夠找到一個列,但所有的列我無法找到總數。請讓我知道是否有人知道答案。 TIA如何查找mysql中所有空值的總數

我想找出每列的總空值計數之和。

FYI 
I don't know all the `column` names in the table. 
+0

是什麼_ 「的所有空的計數」 _?所有空值的計數在哪裏? –

+1

是@AlmaDo。總數值爲NULL。 –

+0

'select count(*)from where where name is null;'?? – 7alhashmi

回答

2

這將得到表中空值的總數。

SELECT SUM(col1 IS NULL) + SUM(col2 IS NULL) + SUM(col3 IS NULL) ... AS NullCount 
FROM YourTable 

如果您需要爲任意表做到這一點,你必須編寫動態SQL,從information_schema數據庫中獲取表和列名。

+0

可能是一個棘手的部分是列數不知道(或可能連他們的名字都不知道) –

0

嘗試這樣:

select sum(case when id is null then 1 else 0 end + 
case when name is null then 1 else 0 end) as count 
from a; 

Example