SELECT * FROM( SELECT date,line_number,machine_number,TIME,VAL FROM( select * from output_tbl unpivot ( VAL for TIME in ([0000HR]) ) uvt )tb1 )tb3 PIVOT ( max(VAL) FOR TIME IN ([0000HR]) )pvt