两个办法:先找出年级排名前十的,然后再根据班级排名即可。
把年级排名和班级排名全部列出,然后再找年级排名前十的。
相对而言第一种办法比较好,二次查询的时候相对内容要少些。
select rownum 年级排名,rank() over( partition by class_no order by score) as 班级排名, name,stu_no,class_no,score from (select name,stu_no,class_no,score from table order by score) where rownum<=10.
第二种写法则是反过来,先排全年级的名次和班级名次,然后再找年级排名前十。这样做的话查询压力比较大。
select * from (select rank() over(order by score) as 年级排名,rank() over( partition by class_no order by score) as 班级排名,name,stu_no,class_no,score from table) where 年级排名<=10