본문 바로가기
SQL

hackerrank Occupations

by 무적김두칠 2022. 11. 13.

https://www.hackerrank.com/challenges/occupations/problem?isFullScreen=true 

 

Occupations | HackerRank

Pivot the Occupation column so the Name of each person in OCCUPATIONS is displayed underneath their respective Occupation.

www.hackerrank.com

 

1
2
3
4
5
6
7
8
9
10
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
cs
반응형

댓글