一张sql的成绩表,查询各科成绩前两名(考虑并列)
遇到一个难题,学生成绩表scores,id,stuid,courid,score

要求查询各科(courid)成绩前两名的stuid,
我自己写了个左连接查询,当成绩没有并列的时候还好,一旦有并列,就不对了,求指教。最好一步完成,不用top函数
select *
from study.scores s1 left join study.scores s2
on s1.courid=s2.courid and s1.score<s2.score
group by s1.courid,s1.score
having count(s1.id)<2
order by s1.courid,s1.score desc
相关推荐
《查询各科成绩前两名的记录》建表脚本及查询SQL+终极分析.txt
查询各科成绩前两名的记录,包含建表SQL语句+分析!
sql查询出各科成绩最好的学生信息
主要介绍了如何使用sql查询出各科成绩最好的学生信息,需要的朋友可以参考下
sql面试题- (学生表_课程表_成绩表_教师表)
1、查询“001”课程比“002”课程成绩高的所有学生的学号; select a.S# from (select s#,score from SC where C#='001') a,(select s#,score from SC where C#='002') b where a.score>b.score and a.s#=b.s#; 2、查询平均成绩大于60分的同学的学号和平均成绩; select S#,avg(score) from sc group by S# having avg(score) >60; 3、查询所有同学的学号、姓名、选课数、总成绩; select Student.S#,Student.Sname,count(SC.C#),sum(score) from Student left Outer join SC on Student.S#=SC.S# group by Student.S#,Sname 4、查询姓“李”的老师的个数; select count(distinct(Tname)) from Teacher where Tname like '李%'; 5、查询没学过“叶平”老师课的同学的学号、姓名; select Student.S#,Student.Sname from Student where S# not in (select distinct( SC.S#) from SC,Course,Teacher where SC.C#=Course.C# and Teacher.T#=Course.T# and Teacher.Tname='叶平');
mysql 查询语句学生表、课程表、 成绩表、教师表.docx
mysql 查询语句学生表、课程表、 成绩表、教师表.docx
在Sql Sever 2008 中 查询每门课程的前3名
如何查询分类项中的前几条数据,写了3种方法,建议用第2种


