[HR] Occupations

yozzum·2022년 9월 18일
0

SQL

목록 보기
5/25
  • problem : Long to Wide Pivot with sorting

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

  • input
  • output
    Doctor, Professor, Singer, Actor
select max(case when t.occupation = "Doctor" then t.name else null end) as "doctor"
        ,max(case when t.occupation = "Professor" then t.name else null end) as "professor"
        ,max(case when t.occupation = "Singer" then t.name else null end) as "singer"
        ,max(case when t.occupation = "Actor" then t.name else null end) as "actor"
from (select o.*
            ,row_number() over (partition by o.occupation order by o.name) idx
      from occupations o) t
group by t.idx
profile
yozzum

0개의 댓글