sql - SQL查询查找表的每一列中非空值的计数?
问题描述
我可以通过输入每个列名来找到非空值的计数,但是有没有办法在不手动输入列名的情况下编写它,因为我的表中有 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
解决方案
您可以在此处使用案例操作
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
推荐阅读
- c# - 如何按名称查找歌曲并将其从播放列表中删除
- spring - AOP 配置中的问题似乎无效
- batch-file - 用于 nasm 编译器的可点击批处理文件
- reactjs - 反应中的onelogin OIDC令牌刷新
- css - 如何移除锚点 ::after 的悬停效果?
- php - 如何在自定义 php 项目中运行 composer 包
- sharepoint - SharePoint Online 删除网站集
- apache - Apache NiFi 1.6.0 升级后错误
- php - 循环遍历数据库结果似乎只执行一次
- python - 验证确定性有限自动机转换函数对于每个唯一的输入字母表都有一个准确的输出状态