注册 登录
编程论坛 Oracle论坛

一段逻辑,求指导

TsugumiYuu 发布于 2016-06-21 11:43, 5281 次点击
有学院表Student,有数据:
学员id
学员名字name
科目subject
成绩score
班级编码classid
欲求每班每科最高成绩

想请问下我的这段代码能不能解决:
SELECT a.classid,a.subject,b.maxscore
FROM Student a,
(SELECT classid,MAX(score) maxscore FROM a GROUP BY classid) b
WHERE a.classid=b.classid
GROUP BY subject;

纠结了好久,想先分班级,后分科目,但是就晕掉了
2 回复
#2
TsugumiYuu2016-06-21 14:43
顺带问下这段逻辑对不对
SELECT a.name,a.score,a.classid,b.avgscore
FROM Student a,
(SELECT classid,avg(score) avgscore
FROM student
GROUP BY classid) b
WHERE a.classid=b.classid
AND a.score>b.avgscore;
只是写法上有没有问题
#3
super良人2016-08-24 14:59
每科最高成绩:别想太复杂,sql很强大的;
SELECT classid,subject,MAX(score)
FROM Student
GROUP BY subject,classid;
1