67,513
社区成员
发帖
与我相关
我的任务
分享
with temp as
(
select 1991 year,1 month,1.1 amount from dual
union all
select 1991 year,2 month,1.2 amount from dual
union all
select 1991 year,3 month,1.3 amount from dual
union all
select 1991 year,4 month,1.4 amount from dual
union all
select 1992 year,1 month,2.1 amount from dual
union all
select 1992 year,2 month,2.2 amount from dual
union all
select 1992 year,3 month,2.3 amount from dual
union all
select 1992 year,4 month,2.4 amount from dual
)
select * from temp
PIVOT (SUM(amount) FOR month IN (1 as m1,2 as m2,3 as m3,4 as m4) )
YEAR M1 M2 M3 M4
---------- ---------- ---------- ---------- ----------
1991 1.1 1.2 1.3 1.4
1992 2.1 2.2 2.3 2.4
11G的行转列可以用这个方式
如果是10g还是老实的用decode吧
为啥要用分析函数,谁告诉你用了就能提高效率?