Double Group by with percentage summarize- Window Function Postgres

问题描述 投票:0回答:0

我有一个看起来像这样的旅行表enter image description here

我正在尝试对 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 目的地;

这有效,但不是我想要的格式,就是这样。谁能帮忙? enter image description here

postgresql group-by window-functions
© www.soinside.com 2019 - 2024. All rights reserved.