Oracle数据库中的“转置”
统计不同产品类别在不同月份的销量:pivot 和 unpivot
CREATE OR REPLACE VIEW AQKCCKL_NEW_FIN_V AS SELECT T.*, NVL(T.M1,0)+NVL(T.M2,0)+NVL(T.M3,0)+NVL(T.M4,0)+NVL(T.M5,0)+NVL(T.M6,0)+NVL(T.M7,0)+NVL(T.M8,0)+NVL(T.M9,0)+NVL(T.M10,0)+NVL(T.M11,0)+NVL(T.M12,0) TOTAL, round ((NVL(T.M1,0)+NVL(T.M2,0)+NVL(T.M3,0)+NVL(T.M4,0)+NVL(T.M5,0)+NVL(T.M6,0)+NVL(T.M7,0) +NVL(T.M8,0)+NVL(T.M9,0)+NVL(T.M10,0)+NVL(T.M11,0)+NVL(T.M12,0))/12,0) average FROM ( SELECT * FROM (SELECT IMA01,IMA02,IMA021,TA_IMA01,IMA27,IMA271,SFP02,flzl FROM AQKCCKL_NEW_V) PIVOT ( SUM(FLZL) FOR SFP02 IN ('2019-11' M1,'2019-12' M2,'2020-01' M3, '2020-02' M4,'2020-03' M5,'2020-04' M6,'2020-05' M7,'2020-06' M8, '2020-07' M9,'2020-08' M10,'2020-09' M11,'2020-10' M12))) T;