sql查询以查找表中每列中非空值的计数?

jljoyd4f  于 2021-07-29  发布在  Java
关注(0)|答案(1)|浏览(354)

我可以通过键入每个列名来找到非空值的计数,但是有没有一种方法可以在不手动键入列名的情况下编写它,因为我的表中有100多列。

select 'col1Name', count(col1Name) from table where col1Name is null
union
select 'col2Name', count(col2Name) from table where col2Name is null
union ...
select 'col20Name', count(col20Name) from table where col20Name is null
aydmsdu9

aydmsdu91#

你可以在这里使用案例操作

select 
  sum(case when a is null then 1 else 0 end) A,
  sum(case when b is null then 1 else 0 end) B,
  sum(case when c is null then 1 else 0 end) C
from T

相关问题