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 PivotTable as (
select Name, occupation, row_number() over(PARTITION BY occupation order by name) as RowNum from occupations
)
select
Max(Case when occupation ='Doctor' then Name end) as Doctor,
Max(Case when occupation ='Professor' then Name end) as Professor,
Max(Case when occupation ='Singer' then Name end) as Singer,
Max(Case when occupation ='Actor' then Name end) as Actor
from PivotTable
group by RowNum
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 →
with PivotTable as ( select Name, occupation, row_number() over(PARTITION BY occupation order by name) as RowNum from occupations )
select Max(Case when occupation ='Doctor' then Name end) as Doctor, Max(Case when occupation ='Professor' then Name end) as Professor, Max(Case when occupation ='Singer' then Name end) as Singer, Max(Case when occupation ='Actor' then Name end) as Actor from PivotTable group by RowNum