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 doctor as (
select
name,
ROW_NUMBER() OVER(order by name) as rn
from
OCCUPATIONS
where occupation LIKE 'Doctor'
)
, professor as (
select
name,
ROW_NUMBER() OVER(order by name) as rn
from
OCCUPATIONS
where occupation LIKE 'Professor'
)
,singer as (
select
name,
ROW_NUMBER() OVER(order by name) as rn
from
OCCUPATIONS
where occupation LIKE 'Singer'
)
, actor as (
select
name,
ROW_NUMBER() OVER(order by name) as rn
from
OCCUPATIONS
where occupation LIKE 'Actor'
)
SELECT
d.name,
p.name,
s.name,
a.name
FROM
professor p
LEFT JOIN doctor d on d.rn = p.rn
LEFT Join singer s on s.rn = p.rn
LEFT JOIN actor a on a.rn = p.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 →
EASIEST SOLUTION mY SQL
with doctor as ( select name, ROW_NUMBER() OVER(order by name) as rn from OCCUPATIONS where occupation LIKE 'Doctor' ) , professor as ( select name, ROW_NUMBER() OVER(order by name) as rn from OCCUPATIONS where occupation LIKE 'Professor' ) ,singer as ( select name, ROW_NUMBER() OVER(order by name) as rn from OCCUPATIONS where occupation LIKE 'Singer' ) , actor as ( select name, ROW_NUMBER() OVER(order by name) as rn from OCCUPATIONS where occupation LIKE 'Actor' )
SELECT d.name, p.name, s.name, a.name FROM professor p LEFT JOIN doctor d on d.rn = p.rn LEFT Join singer s on s.rn = p.rn LEFT JOIN actor a on a.rn = p.rn