sql - 获取表中所有记录都具有空值的列的列表 - SQL
问题描述
我有一个包含数百万条记录和 50 个奇数列的表,其中许多列对于表中的所有记录都有空值。如何编写一个 SQL 查询来告诉我哪些列具有所有空记录?
解决方案
如果您想知道哪些列具有所有空值,这意味着没有行具有值,则该行的计数将为 0,因此只需检查即可。
select concat_ws(',',
(case when count(col1) = 0 then 'col1' end),
(case when count(col2) = 0 then 'col2' end),
(case when count(col3) = 0 then 'col3' end),
. . .
) as columns_with_all_null_values
from t;
推荐阅读
- vb.net - 简单的 Emgucv 网络摄像头提要似乎存在内存泄漏
- javascript - window.location.href 和 this.router.url 之间的区别?
- android - 创建 IntentService,不调用 onHandleIntent()
- wordpress - WordPress Divi:行设置中内容选项卡中的文本选项已消失
- php - 尝试在表中插入值时所有值都被清除
- assembly - 当 esp 不是非常低时,汇编程序函数不执行
- php - 如何使用 PHP 两次显示相同的 MySQL 查询?
- reactjs - React 测试库:测试属性/prop
- python - 错误“布尔”对象没有属性“find_element_by_id”
- c - 试图调整 sscanf() 以忽略 \n 和 \t