SQL查询以返回每列不同值的数量
对于背景,我正在查询一个大数据库,每个表和数百万行属性数百个属性。我试图找出哪些列根本没有值。
我可以做以下操作:
SELECT
COUNT(DISTINCT col1) as col1,
COUNT(DISTINCT col2) as col2,
...
COUNT(DISTINCT coln) as coln
FROM table;
每当返回1个计数时,我都知道列没有值,很棒。问题在于,这对于重新输入数百次非常繁琐。我该如何以更有效的方式做到这一点?我对SQL只有基本的了解,雅典娜的功能有限,这对我来说更加困难。谢谢
编辑:只是为了澄清一下,计数需要为1的原因是因为该数据库使用空字符串而不是null
For background, I am querying a large database with hundreds of attributes per table and millions of rows. I'm trying to figure out which columns have no values at all.
I can do the following:
SELECT
COUNT(DISTINCT col1) as col1,
COUNT(DISTINCT col2) as col2,
...
COUNT(DISTINCT coln) as coln
FROM table;
Whenever a count of 1 is returned, I know that column has no values, great. The issue is that this is incredibly tedious to retype hundreds of times. How can I do this in a more efficient manner? I only have a fundamental understanding of SQL, and the limited capabilities of Athena makes this more difficult for me. Thank you
Edit: Just to clarify, the reason why the count needs to be 1 is because this database uses empty Strings rather than NULL
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论