我只是记录一下
select *
from (select a.*,b.score,
dense_rank() over(partition by b.classsid order by b.score desc) rn
from student a,score b
where a.studentId=b.id and b.classsid=a.classsid)
where rn<=5
select *
from (select a.*,b.score,
rank() over(partition by b.classsid order by b.score desc) rn
from student a,score b
where a.studentId=b.id and b.classsid=a.classsid)
where rn<=5
已经验证可以的方案
select * from (
select t.id , t.sname , t.china , t.math , t.english ,
t.glass,t.china + t.math + t.english as total,dense_rank()
over(partition by t.glass order by t.china + t.math + t.english desc) a from t_score t
)where a<=5 order by total desc
还有一种比较熟悉的方案
Select a.*,(a.china + a.math + a.english) sums
From t_score a
Where (Select Count(*)
From t_score b
Where a.glass = b.glass
And (a.china + a.math + a.english) <
(b.china + b.math + b.english)) < 3
order by a.glass,sums desc