Double Group by with percentage summarize- Window Function Postgres
问题描述投票:0回答:0
我有一个看起来像这样的旅行表
我正在尝试对 Postgres 中的目的地和种族进行分组和总结。
我用了这个窗口函数
与 x AS (
选择目的地、种族、计数(activity_id)作为 total_dest_trips
从测试
按目的地、种族分组
)
选择目的地、种族、total_dest_trips*100/sum(total_dest_trips) OVER (PARTITION BY destination_trct) AS share
FROM x ORDER BY 目的地;