简体   繁体   中英

How can i use a Count distinct values in SQL?

How can I do in SQL a:

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).

Empty clearly does not mean NULL , because that is not counted. Let me assume it means an empty string, '' . If so:

select count(distinct nullif(field, ''))

@Gordon Linoff给出的答案就是解决方案!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM