• + 0 comments

    SQL Server

    with ect as ( select *, rank () over (partition by Occupation order by Name ) as Ranking from OCCUPATIONS ) select [Doctor],[Professor],[Singer],[Actor] from ect pivot ( max(Name) for Occupation in ([Doctor],[Professor],[Singer],[Actor])

    )as pivot_table order by case when [Doctor] is Null then 1 else 0 end, [Doctor] asc