[英]How can i use a Count distinct values in SQL?
How can I do in SQL a: 如何在SQL中执行以下操作:
select count(distinct(field))
from table
and the final result don not count empty values? 最后的结果不算空值吗?
example: 例:
the final result should be 3 but it shows 4 (due to empty value). 最终结果应为3,但显示为4(由于为空值)。
Empty clearly does not mean NULL
, because that is not counted. 明确为空并不意味着NULL
,因为不计算在内。 Let me assume it means an empty string, ''
. 让我假设这意味着一个空字符串, ''
。 If so: 如果是这样的话:
select count(distinct nullif(field, ''))
@Gordon Linoff给出的答案就是解决方案!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.