Я бы использовал row_number()
для ранжирования имен для каждой профессии, а затем условное агрегирование для поворота набора данных:
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 o.*, row_number() over(partition by occupation order by name) rn
from occupations o
) t
group by rn
Демонстрация на DB Fiddle
Пример данных:
name | occupation
:-------- | :---------
Samantha | Doctor
Julia | Actor
Maria | Actor
Meera | Singer
Ashely | Professor
Ketty | Professor
Christeen | Professor
Jane | Actor
Jenny | Doctor
Priya | Singer
Результаты:
doctor | professor | singer | actor
:------- | :-------- | :----- | :----
Jenny | Ashely | Meera | Jane
Samantha | Christeen | Priya | Julia
<em>null</em> | Ketty | <em>null</em> | Maria