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;