1.创建测试表

create table a_test_col(t varchar(20),a1 int,a2 int,a3 int)

insert into a_test_col
select 'A',1,2,3
union all
select 'B',0,9,5

 

查询该表

SELECT * FROM a_test_col

postgres/greenplum  unnest(Array) 实现列转行

 

2.通过 unnest(Array) 实现列转行

select T, -- 聚合列
unnest(Array['a1','a2','a3']) as colname, -- 转换的列明 col
unnest(Array[a1,a2,a3]) as colvalue -- 转换的列内容 colvalue
FROM a_test_col

 

postgres/greenplum  unnest(Array) 实现列转行

 

相关文章:

  • 2022-12-23
  • 2022-01-24
  • 2021-10-29
  • 2022-12-23
  • 2021-04-12
  • 2022-12-23
  • 2022-12-23
  • 2021-12-07
猜你喜欢
  • 2022-12-23
  • 2021-10-01
  • 2022-12-23
  • 2022-12-23
  • 2021-05-26
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案