行转列
作者:互联网
点击查看代码
create table test6
(
year number,
month number,
amount number
)
--drop table test6 ---建立表数据
select * from test6 for update
select year,
max(decode(month,1,amount)) m1, ---decode
max(decode(month,2,amount)) m2,
max(decode(month,3,amount)) m3,
max(decode(month,4,amount)) m4
from test6
group by year
with test61 as
(select * from test6
pivot ( max(amount) for month in
(1 as m1,2 as m2,3 as m3,4 as m4))
)
select * from test61
unpivot ( amount for month in (m1 as 1,m2 as 2,m3 as 3,m4 as 4))2,3 as m3,4 as m4))
)
select * from test61
unpivot ( amount for month in (m1 as 1,m2 as 2,m3 as 3,m4 as 4))
标签:test6,m4,month,decode,转列,amount,select 来源: https://www.cnblogs.com/1241187306qq/p/16200317.html