我尝试得到结果3,5没有计数重复,NUll值和空数据。
select count(distinct no1), count(distinct no1) + count(distinct no2) from abc where no1
is not null
答案 0 :(得分:1)
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
试试这个
答案 1 :(得分:1)
如果你不想要null和空,请试试这个:
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
等...像这些聚合函数一样不会{{1作为计算对象。所以只需将空值改为null
,这里使用null
来执行此操作,然后case when
将获得您想要的内容。