1

I want to transpose table below

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 

to

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

how can I pivot multiple columns ? Thanks for any help

1 Answer 1

2

You can consecutively apply UNPIVOT and PIVOT as

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") )

Demo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.