728x90
반응형
https://www.hackerrank.com/challenges/occupations/problem?isFullScreen=true
문제
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.
Input Format
The OCCUPATIONS table is described as follows:
Occupation will only contain one of the following values: Doctor, Professor, Singer or Actor.
Code
select
min(case when occupation = 'Doctor' then name end) 'Doctor',
min(case when occupation = 'Professor' then name end) 'Professor',
min(case when occupation = 'Singer' then name end) 'Singer',
min(case when occupation = 'Actor' then name end) 'Actor'
from (select *, row_number() over (partition by occupation order by name) rn
from occupations) t
group by rn
728x90
반응형
'SQL > MySQL' 카테고리의 다른 글
[MySQL/HackerRank] New Companies (0) | 2023.08.29 |
---|---|
[MySQL/HackerRank] Binary Tree Nodes (0) | 2023.08.29 |
[MySQL/HackerRank] The Report (0) | 2023.08.29 |
[MySQL/HackerRank] Weather Observation Station 5 (0) | 2023.08.29 |
[MySQL/HackerRank] Draw The Triangle 2 (0) | 2023.08.29 |