0; 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 having col0=0000 or d+col0>000 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 having col0=0000 or d+col0>000 order by d, avg(distinct(c)); 