成绩表S,字段sid,cid,score 求每门课程的前2名与后2名sid
with a as (select sid, rank() over(distribute by cid sort by score) `rn`, rank() over(distribute by cid sort by score desc) `rn1` from tmp) select sid,rn,rn1 from a where a.rn<3 or a.rn1<3