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.
select
max(case when t.occupation ='Doctor' then t.name end) as Doctor,
max(case when t.occupation ='professor' then t.name end ) as professor,
max(case when t.occupation ='singer' then t.name end) as singer,
max(case when t.occupation ='actor' then t.name end) as actor
from
( select occupation ,name ,
row_number() over (partition by occupation order by name) as rn
from occupations ) as t
group 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 →
select max(case when t.occupation ='Doctor' then t.name end) as Doctor, max(case when t.occupation ='professor' then t.name end ) as professor, max(case when t.occupation ='singer' then t.name end) as singer, max(case when t.occupation ='actor' then t.name end) as actor from ( select occupation ,name , row_number() over (partition by occupation order by name) as rn from occupations ) as t group by rn