PostgreSQL 列转行问题

  • Post author:
  • Post category:其他



1 测试表数据

SELECT

relative_label_content

FROM

frk_s.label_cor_gene

relative_label_content

——

AA

BB

CC


2 列转行写法


写法1:(string_agg)

SELECT

frwybs,

string_agg (relative_label_content, ‘,’) as relative_label_content

FROM

frk_s.label_cor_gene

GROUP BY

frwybs

relative_label_content

————

AA,BB,CC


写法2: array_to_string(ARRAY_AGG (text),’,’)

SELECT

frwybs,

array_to_string(

ARRAY_AGG (DISTINCT relative_label_content),

‘,’

)  as labels_content

FROM

frk_s.label_cor_gene

GROUP BY

frwybs

labels_content

————

AA,BB,CC



版权声明:本文为HSH205572原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。