PostgreSQL
 sql >> Database >  >> RDS >> PostgreSQL

Efficiente espressione GROUP BY a CASE in Amazon Redshift/PostgreSQL

Lo faresti con due aggregazioni:

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;