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 asc) as r from occupations
),
doc as (select name,r from cte where occupation = 'Doctor'),
prof as (select name,r from cte where occupation = 'Professor'),
si as (select name,r from cte where occupation = 'Singer'),
act as (select name,r from cte where occupation = 'Actor')
select doc.name,prof.name,si.name,act.name
from prof
left join doc on prof.r=doc.r
left join si on prof.r=si.r
left join act on prof.r=act.r
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 asc) as r from occupations ), doc as (select name,r from cte where occupation = 'Doctor'), prof as (select name,r from cte where occupation = 'Professor'), si as (select name,r from cte where occupation = 'Singer'), act as (select name,r from cte where occupation = 'Actor') select doc.name,prof.name,si.name,act.name from prof left join doc on prof.r=doc.r left join si on prof.r=si.r left join act on prof.r=act.r