在postgres中,将某些重复出现的列转换为行。

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

我在Postgres中有一张表,有大约5000万行。我需要将某些列转换为行。

enter image description here

我需要将某些作为单独列重复的个人列拆分,并针对各自的ID重复非个人变量----------。

以下是我需要的输出

enter image description here

Id appreciate any help on this.

postgresql unpivot greenplum
1个回答
0
投票

5000万行在Greenplum中并不是什么大问题,但是把这么多行返回给客户端就有点没意思了。我猜你要为这个新的输出创建一个新表。你也要创建一个2倍大的表,因为你要把一个单行变成2行。

create table new_table as
select id, mid_1 as mid, name_1 as name, age_1 as age, location
from your_table
union all
select id, mid_2 as mid, name_2 as name, age_2 as age, location
from your_table
distributed by (id);
© www.soinside.com 2019 - 2024. All rights reserved.