본문 바로가기
언어

mysql에 pivot 없음

by 땅호720 2024. 6. 14.
with n as (
select *, row_number() over (partition by occupation order by name) rn
from occupations)

select min(if(occupation='Doctor', name, null)) 'Doctor',
        min(if(occupation='Professor', name, null)) 'Professor',
        min(if(occupation='Singer', name, null)) 'Singer',
        min(if(occupation='Actor', name, null)) 'Actor'
from n
group by rn

/*
select Doctor, Professor, Singer, Actor
from n
pivot (
  max(name)
  for occupation in (Doctor, Professor, Singer, Actor)
) as pivotTable
*/

'언어' 카테고리의 다른 글

Symmetric Pairs  (0) 2024.06.19
with as  (0) 2024.06.18
basic join: top competitors (medium)  (1) 2024.06.14
basic join: the report (medium)  (0) 2024.06.13
median: percent_rank  (0) 2024.06.12