取每个班前5名成绩的sql
最近遇到的一道面试题:
select
class,id,
name
,score,rn
from
(
select
class,id,
name
,score,
row_number() over(partition
by
class
order
by
score
desc
)
'rn'
from
学生总表) t
where
t.rn<=5
get 到了
select
class,id,
name
,score,rn
from
(
select
class,id,
name
,score,
row_number() over(partition
by
class
order
by
score
desc
)
'rn'
from
学生总表) t
where
t.rn<=5