Transpose a query output

后端 未结 4 1477
慢半拍i
慢半拍i 2021-01-17 05:26

I have a normal select query which results following output.

select cid,x1,x2,x3,x4,fy
  from temp_table;

cid     x1  x2  x3  x4  fy
-----------------------         


        
4条回答
  •  情歌与酒
    2021-01-17 06:19

    You can do it with combination of unpivot and pivot.

    select * from 
        (select * from 
        (select x1,x2,x3,x4,fy from table1) 
        unpivot(val for x in (x1,x2,x3,x4)))
    pivot(sum(val) for fy in (2014,2015,2016))
    

提交回复
热议问题