• + 0 comments

    set @r_Doctor = 0, @r_Professor = 0,@r_Singer = 0,@r_Actor = 0; select min(Doctor),min(Professor),min(Singer),min(Actor) from( select case when OCCUPATION = 'Doctor' then (@r_Doctor:= @r_Doctor + 1) when OCCUPATION = 'Professor' then (@r_Professor:= @r_Professor + 1) when OCCUPATION = 'Singer' then (@r_Singer:= @r_Singer + 1) when OCCUPATION = 'Actor' then (@r_Actor:= @r_Actor + 1) end as row_num, case when OCCUPATION = 'Doctor' then name else NULL end as Doctor, case when OCCUPATION = 'Professor' then name else NULL end as Professor, case when OCCUPATION = 'Singer' then name else NULL end as Singer, case when OCCUPATION = 'Actor' then name else NULL end as Actor from OCCUPATIONS order by name ) as tbl group by row_num;