Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 在两个不同的列中只计算空值,并在一个select语句中显示_Mysql_Sql_Database_Select_Count - Fatal编程技术网

Mysql 在两个不同的列中只计算空值,并在一个select语句中显示

Mysql 在两个不同的列中只计算空值,并在一个select语句中显示,mysql,sql,database,select,count,Mysql,Sql,Database,Select,Count,我只想计算一个特定列中的空值和另一列中的所有空值 但是,我希望我的结果在一个表中显示这两个结果 以下是我到目前为止的情况: Select Count(*) as 'Column1Count', Count(*) as 'Column2Count' from table1 Where column1 is null and column2 is null 请帮助这应该可以: select (select count(*) from table1 where

我只想计算一个特定列中的空值和另一列中的所有空值 但是,我希望我的结果在一个表中显示这两个结果

以下是我到目前为止的情况:

Select Count(*) as 'Column1Count', Count(*) as 'Column2Count'
   from table1
       Where column1 is null
     and column2 is null
请帮助

这应该可以:

select
    (select count(*) from table1 where column1 is null) as 'Column1Count',
    (select count(*) from table1 where column2 is null) as 'Column2Count';

您可以使用一个案例:

select  sum(case when Column1 is null then 1 end) as Col1Count
,       sum(case when Column2 is null then 1 end) as Col2Count
from    table1

谢谢,这个查询中的案例我从未使用过,但这给了我正确的输出