
添加辅助列cur_rank非常重要,这是分类的依据,此外null值和非空值进行比较时,null认为是最小的
select
max(case when continent = 'America' then name else null end) America,
max(case when continent = 'Asia' then name else null end) Asia,
max(case when continent = 'Europe' then name else null end) Europe
from
(select
name,
continent,
row_number()over(partition by continent order by name) cur_rank
from
student)t
group by cur_rank
浙公网安备 33010602011771号