题目:力扣 

方法一:排序+max函数

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

方法二:with函数

with A as 
(   select  America, row_number() over() as rA from
        (select case when continent = 'America' then name end as America from Student) a
    where America is not NULL
    order by America
)
    ,B as 
(   select  Asia , row_number() over() as rB from
        (select case when continent = 'Asia ' then name end as Asia  from Student) b
    where Asia  is not NULL
    order by Asia
)
    ,C as 
(   select  Europe , row_number() over() as rC from
        (select case when continent = 'Europe ' then name end as Europe  from Student) c
    where Europe  is not NULL
    order by Europe
)

select America, Asia, Europe from A a 
left join B b
on a.rA = b.rB
left join C c
on a.rA = c.rC
Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐