Que: 3. 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.
Pivot the Occupation column in OCCUPATIONS
Input Format: The OCCUPATIONS table is described as follows:

Occupation will only contain one of the following values: Doctor, Professor, Singer, or Actor.
Sample Input

Sample Output
Jenny Ashley Meera Jane
Samantha Christeen Priya Julia
NULL Ketty NULL Maria
![Que: 3. 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. [10] Note: Print Null When There Are No More Names Corresponding To An Occupation. Que: 3. 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. [10]
Note: Print Null When There Are No More Names Corresponding To An Occupation.](https://sp-ao.shortpixel.ai/client/to_webp,q_glossy,ret_img,w_506,h_231/https://speedjobalert.com/wp-content/uploads/2021/11/image-edited.png)
Explanation
The first column is an alphabetically ordered list of Doctor names.
The second column is an alphabetically ordered list of Professor names.
The third column is an alphabetically ordered list of Singer names.
The fourth column is an alphabetically ordered list of Actor names.
The empty cell data for columns with less than the maximum number of names per occupation (in this case, the Professor and Actor columns) are filled with NULL values.
Solution of Pivot the Occupation column in OCCUPATIONS
Solution
create table occupations(name varchar(50), occupation varchar(50))
INSERT INTO occupations(name, occupation) values('Samantha','Doctor')
INSERT INTO occupations(name, occupation) values('Julia','Actor')
INSERT INTO occupations(name, occupation) values('Maria','Actor')
INSERT INTO occupations(name, occupation) values('Meera','Singer')
INSERT INTO occupations(name, occupation) values('Ashely','Professor')
INSERT INTO occupations(name, occupation) values('Ketty','Professor')
INSERT INTO occupations(name, occupation) values('Christeen','Professor')
INSERT INTO occupations(name, occupation) values('Jane','Actor')
INSERT INTO occupations(name, occupation) values('Jenny','Doctor')
INSERT INTO occupations(name, occupation) values('Priya','Singer')

select doctor,professor,singer,actor from
(
select * from (select name, occupation, (ROW_NUMBER() OVER
(PARTITION BY occupation ORDER BY name)) as row_num
from occupations order by name asc) pivot ( min(name) for
occupation in ('Doctor' as doctor,'Professor' as professor,'Singer' as singer,'Actor' as actor))
order by row_num)

ORACLE Live SQL: https://livesql.oracle.com/apex/f?p=590:1000
Download Source Code: đ
Candidates having any kind of query so he/she can ask in our comment section. Our Panel will b reverting back as soon as possible. Thank You. For more details visit our website (https://speedjobalert.com/)
select doctor,professor,singer,actor from
(
select * from (select name, occupation, (ROW_NUMBER() OVER
(PARTITION BY occupation ORDER BY name)) as row_num
from occupations order by name asc) pivot ( min(name) for
occupation in (‘Doctor’ as doctor,’Professor’ as professor,’Singer’ as singer,’Actor’ as actor))
order by row_num)
THE ADVANCE PROBLEM FROM OCCUPATION IN SQL HACKER RANK IS NOT GIVING OUTPUT
SHOWING ERROR AFTER PIVOT SO PLEASE HELP
— change âDoctorâ single quotation to ‘Doctor’
select doctor,professor,singer,actor from
(
select * from (select name, occupation, (ROW_NUMBER() OVER
(PARTITION BY occupation ORDER BY name)) as row_num
from occupations order by name asc) pivot ( min(name) for
occupation in (‘Doctor’ as doctor,’Professor’ as professor,’Singer’ as singer,’Actor’ as actor))
order by row_num)