成績(jī)表S,字段sid,cid,score
求每門(mén)課程的前2名與后2名sid
下面是我的做法,求個(gè)更好的
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