select coalesce(Doctor, 'NULL'),
coalesce(Professor, 'NULL'),
coalesce(Singer, 'NULL'),
coalesce(Actor, 'NULL')
from (select name,
occupation,
row_number() over(partition by occupation order by name) rn
from occupations
where occupation in ('Doctor', 'Professor', 'Singer', 'Actor'))
pivot(max(name)
for occupation in('Doctor' as Doctor,
'Professor' as Professor,
'Singer' as Singer,
'Actor' as Actor))
order by Doctor, Professor, Singer, Actor
coalesce(Professor, 'NULL'),
coalesce(Singer, 'NULL'),
coalesce(Actor, 'NULL')
from (select name,
occupation,
row_number() over(partition by occupation order by name) rn
from occupations
where occupation in ('Doctor', 'Professor', 'Singer', 'Actor'))
pivot(max(name)
for occupation in('Doctor' as Doctor,
'Professor' as Professor,
'Singer' as Singer,
'Actor' as Actor))
order by Doctor, Professor, Singer, Actor