We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Occupations
You are viewing a single comment's thread. Return to all 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