[HR] Occupations

yozzum·2022년 9월 18일

SQL

목록 보기
5/36
  • 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 o.occupation = 'Doctor' then o.name else null end) as "Doctor"
      ,max(case when o.occupation = 'Professor' then o.name else null end) as "Professor"
      ,max(case when o.occupation = 'Singer' then o.name else null end) as "Singer"
      ,max(case when o.occupation = 'Actor' then o.name else null end) as "Actor"
from (
    select name
      ,occupation
      ,row_number() over (partition by occupation order by name) as idx
    from occupations) o
group by o.idx
order by o.idx;

profile
yozzum

0개의 댓글