• + 0 comments

    My Solution:

    with t1 as ( select distinct name, 
            row_number() over (order by name) id
                from occupations
                where lower(occupation) = 'doctor'
                ),
    t2 as  ( select distinct name, 
            row_number() over (order by name) id
                from occupations
                where lower(occupation) = 'professor'
                ),  
    t3 as  ( select distinct name, 
            row_number() over (order by name) id
                from occupations
                where lower(occupation) = 'singer'
                ),  
    t4 as  ( select distinct name, 
            row_number() over (order by name) id
                from occupations
                where lower(occupation) = 'actor'
                )
    select distinct t1.name, t2.name, t3.name, t4.name
    from t1
    full outer join t2
    on t1.id = t2.id
    full outer join t3
    on t2.id = t3.id
    full outer join t4
    on t3.id = t4.id
    order by 1, 2, 3, 4;