oracle sql转置表

pgccezyw  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(384)

我想调换下表

NAME                  BRUT      MALIYET     NET
------------------------------------------------
BAZ ÜCRET             16944,44  16944,44    16944,44
MESAİ                 0         0           0
SABİT PRİMLER         6452,46   6452,46     6452,46
PERFORMANS PRİMİ      0         0           0
DİĞER ÖDEMELER        0         0           0
İŞÇİ SGK ÖDEMESİ      3278,27   3278,27 
İŞVEREN SGK ÖDEMESİ             4314,35

NAME   BAZ ÜCRET  MESAİ    SABİT PRİMLER    PERFORMANS PRİMİ   DİĞER ÖDEMELER   İŞÇİ SGK ÖDEMESİ  İŞVEREN SGK ÖDEMESİ 
 ----------------------------------------------------------------------------------------------------------------------    
NET      16944,44   0       6452,46           0                  0                NULL            NULL
BRUT     16944,44   0       6452,46           0                  0                3278,27         NULL         
MALIYET  16944,44   0       6452,46           0                  0                3278,27         4314,35

如何透视多个列?谢谢你的帮助

m0rkklqb

m0rkklqb1#

您可以根据需要连续应用unpivot和pivot

WITH t AS
(
SELECT *
  FROM tab  --> this stands for your original table
UNPIVOT (deger FOR "Odeme Turu" IN ( brut, maliyet, net ))
)
SELECT * 
  FROM t
 PIVOT (MAX(deger) FOR name IN ('BAZ UCRET'           AS "Baz Ucret",
                                'MESAI'               AS "Mesai",
                                'SABIT PRIMLER'       AS "Sabit Primler", 
                                'PERFORMANS PRIMI'    AS "Performans Primi",
                                'DIGER ODEMELER'      AS "Diger Odemeler",
                                'ISCI SGK ODEMESI'    AS "Isci SGK Odemesi",
                                'ISVEREN SGK ODEMESI' AS "Isveren SGK Odemesi") )

演示

相关问题