PIVOT Operators in Oracle

PIVOT Operators in Oracle
--=======================================================


--====================================================

select * from XX_SUP_GST_DET_TL
 WHERE SUPPLIER_CODE in ( '1b7718','24ec85','33767e','35a382')
ORDER BY 3

INVOICE_NUMBER
TYPE
SUPPLIER_CODE
TAX_AMOUNT
LINE_TYPE
1920HR/CN/183427
GST_CM
1b7718
-783.52
IGST
1920HR/CN/183428
GST_CM
1b7718
-99084.91
IGST
1920HR/CN/183429
GST_CM
1b7718
-8682.69
IGST
1920HR/CN/183430
GST_CM
1b7718
-4516.55
IGST
1920DL/CN/580
GST_CM
1b7718
-189.39
IGST
1920HR/IN/116046
GST_INV
1b7718
488309.37
IGST
1920HR/CN/196864
GST_CM
24ec85
-216.33
CGST
1920HR/IN/124151
GST_INV
24ec85
7029.14
SGST
1920HR/IN/124151
GST_INV
24ec85
7029.14
CGST
1920HR/CN/196865
GST_CM
24ec85
-2366.45
SGST
1920HR/CN/196865
GST_CM
24ec85
-2366.45
CGST
1920HR/CN/196864
GST_CM
24ec85
-216.33
SGST
1920HR/CN/199320
GST_CM
33767e
-3199.34
CGST
1920HR/IN/125664
GST_INV
33767e
20414.48
CGST
1920HR/CN/199320
GST_CM
33767e
-3199.34
SGST
1920HR/IN/125664
GST_INV
33767e
20414.48
SGST
1920HR/IN/117499
GST_INV
35a382
180.38
SGST
1920HR/IN/117499
GST_INV
35a382
180.38
CGST


--================== Select onlt below columns fro PIVOT ============

select SUPPLIER_CODE, TYPE, TAX_AMOUNT, LINE_TYPE 
from XX_SUP_GST_DET_TL
where  SUPPLIER_CODE in ( '1b7718','24ec85','33767e','35a382')


TYPE
SUPPLIER_CODE
TAX_AMOUNT
LINE_TYPE
GST_CM
1b7718
-783.52
IGST
GST_CM
1b7718
-99084.91
IGST
GST_CM
1b7718
-8682.69
IGST
GST_CM
1b7718
-4516.55
IGST
GST_CM
1b7718
-189.39
IGST
GST_INV
1b7718
488309.37
IGST
GST_CM
24ec85
-216.33
CGST
GST_INV
24ec85
7029.14
SGST
GST_INV
24ec85
7029.14
CGST
GST_CM
24ec85
-2366.45
SGST
GST_CM
24ec85
-2366.45
CGST
GST_CM
24ec85
-216.33
SGST
GST_CM
33767e
-3199.34
CGST
GST_INV
33767e
20414.48
CGST
GST_CM
33767e
-3199.34
SGST
GST_INV
33767e
20414.48
SGST
GST_INV
35a382
180.38
SGST
GST_INV
35a382
180.38
CGST

--================PIVOT Syntax with example =================


select * from
( select SUPPLIER_CODE, TYPE, TAX_AMOUNT, LINE_TYPE 
from XX_SUP_GST_DET_TL
where  SUPPLIER_CODE in ( '1b7718','24ec85','33767e','35a382')
) 
PIVOT (SUM(TAX_AMOUNT) AS AMOUNT FOR (LINE_TYPE) IN (  
  'SGST' SGST     
, 'CGST' CGST
, 'IGST' IGST
 )  )
ORDER BY 1



SUPPLIER_CODE
TYPE
SGST_AMOUNT
CGST_AMOUNT
IGST_AMOUNT
1b7718
GST_CM


-113257.06
1b7718
GST_INV


488309.37
24ec85
GST_CM
-2582.78
-2582.78

24ec85
GST_INV
7029.14
7029.14

33767e
GST_CM
-3199.34
-3199.34

33767e
GST_INV
20414.48
20414.48

35a382
GST_INV
180.38
180.38






Comments

Popular posts from this blog

E-Text Report In Fusion | Types of E-Text reports

Supplier API's

How to pass default Parameter in cursor