sql >> Base de Datos >  >> RDS >> PostgreSQL

GRUPO Eficiente POR una expresión CASE en Amazon Redshift/PostgreSQL

Haría esto con dos agregaciones:

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;