Rupal Patel

Rupal Patel

  • 1.7k
  • 31
  • 1.1k

Pivot Table in Oracle

May 2 2024 6:56 PM

Hi,

My data is like this formate.-Using Query

SELECT DISTINCT W.CONTRACTNUM, W.STARTDATE,W.POSITIONDESC, W.RATE801

FROM BI_HZ_ETL.LEM_CNRLEMCRAFTRATE W

WHERE W.CONTRACTNUM='A689'

GROUP BY W.CONTRACTNUM,W.POSITIONDESC,W.STARTDATE,W.RATE801

ORDER BY W.CONTRACTNUM,W.POSITIONDESC,W.STARTDATE

CONTRACTNUM POSITIONDESC RATE801 STARTDATE
A689 ACC+PR 71.88 2/6/2022
A689 ACC+PR 72.77 1/1/2023
A689 ACC+PR 73 1/1/2024
A689 ADM+L1 45.07 2/6/2022
A689 ADM+L1 47.86 1/1/2023
A689 ADM+L1 48.01 1/1/2024
A689 ADM+TK 53.11 2/6/2022
A689 ADM+TK 56.41 1/1/2023
A689 ADM+TK 56.58 1/1/2024
A689 CO+HSE/DSP 93.15 1/1/2023
A689 CO+HSE/DSP 93.15 1/1/2024
A689 CO+MAT 67.35 2/6/2022
A689 CO+MAT 72.23 1/1/2023
A689 CO+MAT 72.46 1/1/2024
A689 CO+PR 71.88 2/6/2022
A689 CO+PR 76.37 1/1/2023
A689 CO+PR 76.61 1/1/2024
A689 DRV+PRIN 70.74 11/6/2022
A689 DRV+PRIN 71.82 1/1/2023
A689 DRV+PRIN 73.4 3/5/2023
A689 DRV+PRIN 77.12 11/5/2023
A689 DRV+PRIN 77.33 1/1/2024
A689 DRV+PRIN/CST/TB1 73.99 11/6/2022
A689 DRV+PRIN/CST/TB1 75.11 1/1/2023
A689 DRV+PRIN/CST/TB1 76.69 3/5/2023
A689 DRV+PRIN/CST/TB1 80.38 11/5/2023
A689 DRV+PRIN/CST/TB1 80.61 1/1/2024

I would like to have data output like below

CONTRACTNUM POSITIONDESC Rate1 Change_date1 Rate2 Change_date2 Rate3 Change_date3 Rate4 Change-date4 Rate5 Change_date5
A689 ACC+PR 71.88 2/6/2022 72.77 1/1/2023            
A689 ADM+L1 45.07 2/6/2022 47.86 1/1/2023 47.01 1/1/2024        
A689 ADM+TK 53.11 2/6/2022 56.41 1/1/2023 55.58 1/1/2024        
A689 CO+HSE/DSP 93.15 1/1/2023 93.15 1/1/2024            
A689 CO+MAT 67.35 2/6/2022 72.23 1/1/2023 71.46 1/1/2024        
A689 CO+PR 71.88 2/6/2022 76.37 1/1/2023 75.61 1/1/2024        
A689 DRV+PRIN 70.74 11/6/2022 71.82 1/1/2023 73.4 3/5/2023 77.12 11/5/2023 77.33 1/1/2024
A689 DRV+PRIN/CST/TB1 73.99 11/6/2022 75.11 1/1/2023 76.69 3/5/2023 80.38 11/5/2023 80.61 1/1/2024

Answers (9)