PostgreSQL
 sql >> Base de Dados >  >> RDS >> PostgreSQL

Eficiente GROUP BY a CASE expression no Amazon Redshift/PostgreSQL


Você faria isso com duas agregações:
select type, (case when cnt > XXX then url end) as url, sum(cnt) as visit_cnt
from (select type, url, count(*) as cnt
      from t
      group by type, url
     ) t
group by type, (case when cnt > XXX then url end)
order by type, sum(cnt) desc;