I have a requirement in oracle SQL where the multiple rows are to be converted into single row.
Here is the example :
Empid Ele_name Inp_name Inp_Value EntryId Start_date End Date
123 LW MA 1637 100000104856397 06-Nov-17 31-Dec-12
123 LW CA Y 100000104856397 06-Nov-17 31-Dec-12
143 LW MA 1637 100000104856504 06-Nov-17 31-Dec-12
143 LW CA Y 100000104856504 06-Nov-17 31-Dec-12
144 MTS AA 1000 300002685277016 12-Dec-17 31-Dec-12
144 MTS CA Y 300002685277016 12-Dec-17 31-Dec-12
144 LW CA Y 300002685277012 06-Nov-17 31-Dec-12
144 LW AA 200 300002685277012 06-Nov-17 31-Dec-12
The expected output is
Empid Element_name FIrstName LastName Initials Input_name1 Input_Value1 Input_name2 Input_Value2 Input_name3 Input_Value3 Input_name4 Input_Value4 Input_name5 Input_Value5 EntryId Start_date End Date
123 LW null null null MA 1637 CA Y null null null null null null 100000104856397 06-Nov-17 31-Dec-12
143 LW null null null MA 1637 CA Y null null null null null null 100000104856504 06-Nov-17 31-Dec-12
144 MTS null null null AA 1000 CA Y null null null null null null 300002685277016 12-Dec-17 31-Dec-12
144 LW null null null CA Y AA 200 null null null null null null 300002685277012 06-Nov-17 31-Dec-12
I heard that this can be done with Pivot. But i am new to the concept. Can anyone help here.
See Question&Answers more detail:os