SQL查询以返回每列不同值的数量

发布于 2025-01-23 02:56:02 字数 358 浏览 2 评论 0原文

对于背景,我正在查询一个大数据库,每个表和数百万行属性数百个属性。我试图找出哪些列根本没有值。

我可以做以下操作:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文