 select b, c from t_distinct group by b, c order by b, count(distinct(c))-c limit 00; explain (costs off, nodes off) select count(distinct(c)), d from t_distinct group by d having avg(distinct(c)) <> 0 order by 0; select count(distinct(c)), d from t_distinct group by d having avg(distinct(c)) <> 0 order by 0; 