PostgreSQL
 sql >> Datenbank >  >> RDS >> PostgreSQL

Effizient GROUP BY einen CASE-Ausdruck in Amazon Redshift/PostgreSQL

Sie würden dies mit zwei Aggregationen tun:

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;