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 *, row_number() over (partition by occupation order by name) rn
from occupations
) t
group by rn
행과 열을 바꾸는 pivot 을 활용해야 한다.
select 에서 case when 앞에 max 를 쓰는 이유는
로 추정할 수 있겠다 🙃
마지막에 group by rn
이 빠지면 한 줄만 나온다
따라서 빼먹지 말고 꼭 써줘야 한다 !