为什么“SELECT COUNT(DISTINCT< Column>)FROM< Table>”返回0? [英] Why "SELECT COUNT(DISTINCT <Column>) FROM <Table>" return 0?

查看:179
本文介绍了为什么“SELECT COUNT(DISTINCT< Column>)FROM< Table>”返回0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经对大型表中的所有列执行了上面的查询在两种情况下,COUNT(DISTINCT)可以返回零。第一个是列/表达式的所有值计算为 NULL 。第二个是 WHERE 子句(或 JOIN )过滤掉所有行。



如果您没有 WHERE JOIN ,那么值都是 NULL for < Columnb>


I have run the query above for all columns in a massive table (Billion rows) and everything is fine except a couple which are returning 0. How is this possible?

解决方案

COUNT(DISTINCT) can return zero under two circumstances. The first is that all the values for the column/expression evaluate to NULL. The second is that the WHERE clause (or JOIN) filters out all rows.

If you have no WHERE or JOIN, then the values are all NULL for <Columnb>.

这篇关于为什么“SELECT COUNT(DISTINCT&lt; Column&gt;)FROM&lt; Table&gt;”返回0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆