成绩表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