有个成绩表 score(student_no,Subject_no,Score)分别为学号,课程号,成绩。我想用语句查询出每科的前三名学生的学号,请各位高手教教小弟

1.创建测试语句:
create table score(student_no varchar2(3),Subject_no varchar2(20),Score number);
insert into score values('001','语文',70);
insert into score values('001','数学',60);
insert into score values('001','英语',90);

insert into score values('002','语文',78);
insert into score values('002','数学',67);
insert into score values('002','英语',80);

insert into score values('003','语文',89);
insert into score values('003','数学',60);
insert into score values('003','英语',97);

insert into score values('004','语文',50);
insert into score values('004','数学',67);
insert into score values('004','英语',70);

insert into score values('005','语文',79);
insert into score values('005','数学',65);
insert into score values('005','英语',79);

insert into score values('006','语文',74);
insert into score values('006','数学',56);
insert into score values('006','英语',87);
commit;
2.产生结果:
select * from (
select t.*,row_number() over(partition by t.subject_no order by t.score desc) pm from score t) where pm<4;

STUDENT_NO SUBJECT_NO SCORE PM
002 数学 67 1
004 数学 67 2
005 数学 65 3
003 英语 97 1
001 英语 90 2
006 英语 87 3
003 语文 89 1
005 语文 79 2
002 语文 78 3

或者以下SQL:
select* from score s1 where Score in( select Score from score s2
where s2.Subject_no=s1.Subject_no and rownum<=3
)order by s1.Subject_no,s1.Score desc

转自:http://zhidao.baidu.com/link?url=Y3KzpLugzm4HIIJXMlgOQEU-MZmeo0avJ1ZBcQ66DwWtLUaIIP9X3EsVsGCFqXfpBGUaBfcMDoCV2dOSLX8Bdq