• + 0 comments

    with PivotTable as ( select Name, occupation, row_number() over(PARTITION BY occupation order by name) as RowNum 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 PivotTable group by RowNum;

    the first step output:

    name | occupation | RowNum samatha doctor 1 julia actor 1 Maria actor 1 ...

    because the combinations of name and occupation is unique, so in the next step use Max( ) or Min( ) can choose the result and filter the NULL value.

    Doctor | Actor | Singer | Professor samantha ashley meera jane enny ketty null maria ...