This another problem from HackerRank / Advanced Select Challenges called Occupations, Here is the SQL solution in MySQL environment.

Problem Description

Pivot the Occupation column in OCCUPATIONS so that each Name is sorted alphabetically and displayed underneath its corresponding Occupation. The output column headers should be Doctor, Professor, Singer, and Actor, respectively.

Note: Print NULL when there are no more names corresponding to an occupation.

To know the details about the problem visit : Occupations


Please check the snippet for the sql implementation. If you have different approach in mind feel free to share in the comment below.

Originally posted at: by @Thomas-George-T