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.
MySQL:
with ranked as (select name, occupation,
row_number() over (partition by occupation order by name) as 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 Ranked
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 →
MySQL: with ranked as (select name, occupation, row_number() over (partition by occupation order by name) as 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 Ranked Group by rn Order by rn