 explain (costs off, nodes off) select distinct mb from (select max(b) mb from t_distinct order by count(distinct(d))); select distinct mb from (select max(b) mb from t_distinct order by count(distinct(d))); explain (costs off, nodes off) select distinct mb from (select max(b) mb from t_distinct having count(distinct(d))=0); select distinct mb from (select max(b) mb from t_distinct having count(distinct(d))=0); explain (costs off, nodes off) select distinct aabcd from (select avg(a+b+c+d) aabcd from t_distinct having count(distinct(a))=max(a)+0); select distinct aabcd from (select avg(a+b+c+d) aabcd from t_distinct having count(distinct(a))=max(a)+0); explain (costs off, nodes off) select distinct ac from (select avg(c) ac from t_distinct order by count(distinct(a))); select distinct ac from (select avg(c::numeric(00,00)) ac from t_distinct order by count(distinct(a))); explain (costs off, nodes off) select distinct ac from (select avg(c) ac from t_distinct order by count(distinct(d))); select distinct ac from (select avg(c::numeric(00,00)) ac from t_distinct order by count(distinct(d))); 