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 |