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
谢谢,这个查询中的案例我从未使用过,但这给了我正确的输出