sql - 我将如何转置 SQL:Redshift 中的 Sum Case 脚本,是否可以加入信息表?
问题描述
我目前有一个脚本来计算每列中空记录的数量。脚本如下
select sum(case when id is null then 1 else 0 end)id , sum(case when createddate is null then 1 else 0 end)createddate from schema_name.Table_name
结果过来就像
|id|createddate|
|0 | 5 |
有没有办法将其转置以获得类似的结果
|id | 0 |
|created date| 5|
最后,如果可能的话,我可以将其加入信息表(SVV_TABLE_INFO)
解决方案
您可以使用union all
:
select 'id', count(*)
from t
where id is null
union all
select 'createddate', count(*)
from t
where createddate is null;
推荐阅读
- emacs - Dired 忽略目录本地模式值
- shell - Jenkins 管道、外壳和管道
- ruby-on-rails - 如何使用带有 Mongoid 而不是 PostgreSQL 或 SQLite 的 Rails?
- python - libvirt-python CentOS 的构建轮子失败
- laravel - 如何初始化 git repo,因为我在推送 laravel 应用程序时出错
- java - 如何在 LibGDX 中使用鼠标输入旋转对象?
- ios - 在 AVPlayer 中启用/禁用隐藏式字幕
- javascript - `localhost` 在加载远程站点的 iframe 中是什么意思?
- python - 如何使用 pygal 绘制熊猫分组值?
- c# - 如何使用计时器从 Mysql 数据库中检索数据?