 select count(distinct(a))+avg(b) col0, count(c) col0, d from t_distinct group by d having count(distinct(c))>0 order by d; explain (costs off, nodes off) select count(distinct(a)) col0, avg(b) col0, count(c) col0, d from t_distinct group by d order by d, avg(distinct(c)); select count(distinct(a)) col0, avg(b) col0, count(c) col0, d from t_distinct group by d order by d, avg(distinct(c)); explain (costs off, nodes off) select count(distinct(a)) col0, d, avg(b) col0, sum(distinct(a)) col0, avg(distinct(c)) col0 from t_distinct group by d order by d, avg(distinct(c)); select count(distinct(a)) col0, d, avg(b) col0, sum(distinct(a)) col0, avg(distinct(c)) col0 from t_distinct group by d order by d, avg(distinct(c)); explain (costs off, nodes off) select distinct case when min(distinct c)>00 then min(distinct c) else null end as min, count(distinct(b)) from t_distinct group by b