• + 2 comments

    Saw this version and checked how it works.

    select min(temp.Doctor), min(temp.Professor),min(temp.Singer),  min(temp.Actor)
    from(
    	select
    		name,
    		ROW_NUMBER() OVER(PARTITION By Doctor,Professor,Singer,Actor order by name asc) AS Rownum, 
    		case when Doctor=1 then name else Null end as Doctor,
    		case when Professor=1 then name else Null end as Professor,
    		case when Singer=1 then name else Null end as Singer,
    		case when Actor=1 then name else Null end as Actor
    	from
    		occupations 
    	  pivot	(count(occupation) for occupation in(Doctor, Professor, Singer, Actor)) as p
    ) temp
    group by temp.Rownum  ;