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 occupation = 'Doctor' THEN name END) Doctor,
max(CASE WHEN occupation = 'Professor' THEN name END) Professor,
max(CASE WHEN occupation = 'Singer' THEN name END) Singer,
max(CASE WHEN occupation = 'Actor' THEN name END) Actor
from
(select name,
occupation,
row_number() over (partition by occupation order by name asc) rn
from occupations
)
group by rn
order by rn 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 →
Oracle option
select max(CASE WHEN occupation = 'Doctor' THEN name END) Doctor, max(CASE WHEN occupation = 'Professor' THEN name END) Professor, max(CASE WHEN occupation = 'Singer' THEN name END) Singer, max(CASE WHEN occupation = 'Actor' THEN name END) Actor from (select name, occupation, row_number() over (partition by occupation order by name asc) rn from occupations ) group by rn order by rn asc ;