Greenplum行列轉換操作


行轉列

一般行轉列過程需要排序才能保障列的順序正常,所以會使用order by

select  apply_no , 
split_part(string_agg(flow_step||'|'||flow_time,'|'ORDER BY flow_id),'|',1) insure1, 
split_part(string_agg(flow_step||'|'||flow_time,'|'ORDER BY flow_id),'|',2) insure1_time ,
split_part(string_agg(flow_step||'|'||flow_time,'|'ORDER BY flow_id),'|',3) insure2, 
split_part(string_agg(flow_step||'|'||flow_time,'|'ORDER BY flow_id),'|',4) insure2_time ,
 from
(
SELECT s.id AS flow_id,
       s.apply_no, 
       s.real_title AS flow_step, 
       s.updated_at AS flow_time
  FROM  apply_flow_steps s 
 WHERE  step in ('insure1','insure2') 
) ss
group by  apply_no 

列轉行就更加簡單了

select id,regexp_split_to_table(str,E'\\|') str from test1

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM