我尝试得到结果3,5,没有计数重复,NUll值和空数据。
select count(distinct no1), count(distinct no1) + count(distinct no2) from abc where no1
is not null


发布于 2017-02-25 02:53:03
如果不希望空和空,请尝试如下:
select
count(distinct case when no1 = '' then null else no1 end),
count(distinct case when no1 = '' then null else no1 end)
+ count(distinct case when no2 = '' then null else no2 end)
from `tbl`这里见Demo。
解释:count,sum,avg等。像这些聚合函数一样,它不会将null作为其计算对象。因此,只需将空值转换为null,在这里使用case when来完成它,然后count distinct就会得到您想要的。
发布于 2017-02-25 02:25:43
select count(distinct no1), count(distinct no1) + (select count(distinct no2) from abc where no2 is not null and no2<>'') from abc where no1 is not null尝尝这个
https://stackoverflow.com/questions/42451240
复制相似问题