添加辅助列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

 

posted on 2023-02-24 16:02  白的枫叶  阅读(6)  评论(0)    收藏  举报