sql - 如何根据条件获取列名
问题描述
我有以下查询检查列是否为空
select
sum(case when Column_1 is null then 1 else 0 end) as Column_1,
sum(case when Column_2 is null then 1 else 0 end) as Column_2,
sum(case when Column_3 is null then 1 else 0 end) as Column_3,
from TestTable
它给:
Column_1 Column_2 Column_3
0 1 0
我想获取具有空值的列名所以我想要的输出是:
Column_1
Column_3
我怎样才能在 Presto 中做到这一点?从查询返回的输出列名似乎并不容易。
解决方案
一种方法是:
select (case when count(column_1) <> count(*) then 'Column_1;' else '' end) ||
(case when count(column_2) <> count(*) then 'Column_2;' else '' end) ||
(case when count(column_3) <> count(*) then 'Column_3;' else '' end)
from TestTable ;
推荐阅读
- google-maps - 如何在对谷歌搜索的 API 调用之间引入延迟以避免 OVER_QUERY_LIMIT 错误
- java - 我的 Java AWS Lambda 函数的 mvn 包在编译期间无法解析 Lambdalogger 类
- php - 使用随机位置方法显示所有位置
- flutter - Flutter bloc_pattern 返回 NoSuchMethodError
- java - 如何在模块化的 java 11 应用程序中动态加载 Libreoffice jar,而不从自定义类加载器中获取 ClassCastException
- appium-android - 无法实例化 URL
- python - 如何删除嵌套循环乘法重复?
- reactjs - 链接不仅仅在子组件中起作用
- if-statement - 基于下拉单元格的条件数组公式
- android - 未使用 DataSource 调用 BoundaryCallback