with a as (select name,occupation,
row_number() over(partition by occupation order by name) 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 a
group by rn
행에 있던 값을 열로 바꾸는 방식
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 (select name,occupation,
row_number() over(partition by occupation order by name) rn
from occupations) a
group by rn
CTE가 아닌 서브쿼리를 from 절에 사용했다.