oracle 行转列,普通

主要用max,decode函数

Select province_name,Province_Code,Report_Id,
MAX(decode(N1, 1, s2, NULL)) s2,
MAX(decode(N1, 1, n2, NULL)) n2,
Max(Decode(N1, 1, N3, Null)) N3,
Max(Decode(N1, 1, N4, Null)) N4,
Max(Decode(N1, 2, S2, Null)) as "s2-1",
Max(Decode(N1, 2, N2, Null)) "n2-1",
Max(Decode(N1, 2, N3, Null)) "n3-1",
Max(Decode(N1, 2, N4, Null)) "n4-1",
Max(Decode(N1, 3, S2, Null)) "s2-2",
Max(Decode(N1, 3, S3, Null)) "s3-2"
FROM ( select qrp.province_code,ep.province_name, Qrd.report_id,
n1,
n2,
n3,
n4,
S1,
S2,
S3
--row_number() over(PARTITION BY qrp.report_id ORDER BY qrp.province_code,N1 ) rn
From
Quarter_Report_Managment Qrm, Quarter_Report_Province Qrp,Quarter_Report_Detail Qrd ,Eprovince Ep
Where Qrm.Id=Qrp.Report_Id And Qrp.Id=Qrd.Report_Id and ep.code=Qrp.Province_Code
And Qrp.Province_Code In ('HI','LN') And Qrp.Status='2' And Qrd.S6='table4' )
GROUP BY province_name,province_code,report_id;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值