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 CTE AS (
select Name , Occupation , dense_rank() over (partition by Occupation order by Name) rn from OCCUPATIONS )
select [Doctor],[Professor],[Singer],[Actor]
from
(select Name , Occupation , rn from CTE) AS Source_table
PIVOT
(
Max(Name) FOR OCCUPATION IN ([Doctor],[Professor],[Singer ],[Actor])
) AS P order by rn;
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 →
For MS SQL SERVER:
with CTE AS ( select Name , Occupation , dense_rank() over (partition by Occupation order by Name) rn from OCCUPATIONS )
select [Doctor],[Professor],[Singer],[Actor] from (select Name , Occupation , rn from CTE) AS Source_table PIVOT ( Max(Name) FOR OCCUPATION IN ([Doctor],[Professor],[Singer ],[Actor]) ) AS P order by rn;