SQL查询,空值数(每列)

时间:2013-11-19 10:04:24

标签: sql sql-server

我有一个名为Hafizwala的表,其中包含农民姓名,害虫种群1,害虫种群2,播种日期等属性。我必须为以下内容编写查询:

没有。 nulls(对于每一列)

我该怎么写这个查询???

2 个答案:

答案 0 :(得分:1)

请尝试一下,希望它有用

  SELECT COUNT(*)-COUNT(Farmer_Name) As [Farmer Name], COUNT(*)-COUNT(Pest_Population1) As [Pest Population1],
   COUNT(*)-COUNT(Pest_Population2) As  [Pest Population2], COUNT(*)-COUNT(dated) As  [dated]
FROM Hafizwala 

答案 1 :(得分:0)

试试这个

SELECT CASE WHEN Name IS NULL THEN 1 ELSE 0 END +
    CASE WHEN pest_popu1 IS NULL THEN 1 ELSE 0 END +       
    CASE WHEN pest_popu2 IS NULL THEN 1 ELSE 0 END +       
    CASE WHEN sowing_date IS NULL THEN 1 ELSE 0 END 

from table_name