获取 Teradata 表中每列的缺失值和非缺失值的计数
我在 Teradata 中有一个包含以下类似数据的表,我想计算表中每列的总缺失记录和总非缺失记录。
预期结果:
目前我正在使用以下查询
SELECT 'New_York' Column_Name
, SUM(CASE WHEN New_York <> '' THEN 1 ELSE 0 END) Nonmissing
,SUM(CASE WHEN New_York = '' THEN 1 ELSE 0 END) Missing
from Table A
SELECT 'London' Column_Name
, SUM(CASE WHEN London <> '' THEN 1 ELSE 0 END) Nonmissing
,SUM(CASE WHEN London = '' THEN 1 ELSE 0 END) Missing
from Table A
等
任何人都可以提供建议吗?循环遍历所有列以创建单个查询,而不是使用不同的列名多次重复相同的查询。我的表中有大约 430 列,多次重复相同的查询是不可行的。任何建议都将受到高度赞赏。
I have a table with below similar data in Teradata and I want to count the total missing and total non missing records of each column in the table.
Expected result:
Currently I'm using below query
SELECT 'New_York' Column_Name
, SUM(CASE WHEN New_York <> '' THEN 1 ELSE 0 END) Nonmissing
,SUM(CASE WHEN New_York = '' THEN 1 ELSE 0 END) Missing
from Table A
SELECT 'London' Column_Name
, SUM(CASE WHEN London <> '' THEN 1 ELSE 0 END) Nonmissing
,SUM(CASE WHEN London = '' THEN 1 ELSE 0 END) Missing
from Table A
and so on
Can anyone please advice if there is anyway we can loop through all columns to create single query instead of repeating the same query multiple time with different column names. I have around 430 columns in the table and repeating same query multiple time is not feasible. Any advice is highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个。它非常通用的 SQL,它应该适合你。
结果如下:
Try this. Its pretty generic SQL, it should work for you.
Here's the result: