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 *, row_number() over(partition by occupation order by name) rn 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 cte
group by rn
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 →
with cte as (select *, row_number() over(partition by occupation order by name) rn 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 cte group by rn order by rn