查询各科成绩前三名的记录:(不考虑成绩并列情况),显示(学号、课程号、分数) SELECT*FROM(SELECTSC.STUDENT_NO SNO, SC.COURSE_NO CNO, SC.CORE SCORE, ROW_NUMBER()OVER(PARTITIONBYSC.COURSE_NOORDERBYSC.COREDESC) RNFROMHAND_STUDENT_CORE SC) AWHEREA.RN<=3 row_number() OVER (PARTITION BY COL1 ...
条件连接表的s2.score出现次数并不能准确的排列出最高分和最低分,举个例子说明一下:比如不同的学生,同一门课程,都是60分,而且这种情况很多,这就会导致我们上面所说的查询方法错误,有可能60出现的次数甚至超过100分,从而导致排序后出现的最高分成了60分.有多少个学生都是同一门课程相同的分数,我们上面所统计的个...
上面那条答案应该是可以的啊,可能是看起来复杂了点吧,我自己试过是没问题的:SELECT t1.sno,t1.cno,Score FROM SC t1 WHERE EXISTS (SELECT COUNT(1)FROM SC WHERE t1.cno= cno AND t1.score<score HAVING COUNT(1)<3)ORDER BY t1.cno,score DESC 另外还有一种类似的写法:SELECT t1.sno...
from SC inner join Student on SC.S#=Student.S inner join Course on Course.C#=SC.C#) as t where exists(select count(1) from t as d where C#=d.C# and score < d.score having count(1)<3 )请采纳答案,支持我一下。
查询各科成绩前三名的记录:(不考虑成绩并列情况),显示(学号、课程号、分数) SELECT*FROM(SELECTSC.STUDENT_NO SNO, SC.COURSE_NO CNO, SC.CORE SCORE, ROW_NUMBER()OVER(PARTITIONBYSC.COURSE_NOORDERBYSC.COREDESC) RNFROMHAND_STUDENT_CORE SC) AWHEREA.RN<=3 ...