成績表S,字段sid,cid,score
求每門課程的前2名與后2名sid
下面是我的做法,求個更好的
select sid from
(select sid,
rank() over(partition by cid order by score) as RA
from S) as A
union
(select sid,
rank() over(partition by cid order by score DESC) as RB
from S) as B
where RA<3 and RB<3


京公網(wǎng)安備 11010802030320號