Q: The column should be created based on the Occupation like Doctor, Teacher, Sweeper, Lawyer which will contain the names ordered alphabetically.
The table:
Name | Occupation
------------------
Amex | Teacher
Joe | Lawyer
Colin | Doctor
Fenny | Sweeper
Lio | Doctor
James | Teacher
Kevin | Teacher
Megh | Lawyer
Output:
Colin Amex Fenny Joe
Lio James NULL Megh
NULL Kevin NULL NULL
I have tried doing pivoting, bucketing and partitioning yet it's not working.