Occupation Query
Question
You're given a table called "PersonOccupation", which is outlined below. Using SQL, pivot the "occupation" column so that each name is sorted alphabetically and displayed underneath its corresponding occupation. The output column headers should be data scientist, analyst, engineer, and program manager, respectively.
Table: PersonOccupation:
Column Name | Data Type | Description |
---|---|---|
name | String | Name of person |
occupation | string | Person's occupation |
Sample records for PersonOccupation:
name | occupation |
---|---|
sally | data scientist |
terry | analyst |
mary | engineer |
sandy | program manager |
erik | program manager |
crystal | analyst |
Example query output:
data scientist | analyst | engineer | program manager |
---|---|---|---|
sally | crystal | mary | erik |
NULL | terry | NULL | sandy |