现有3个表如下:
S(Sno, Sname, Ssex, Sage, Sdep)
学号,名字,性别,年龄,所在院系
C(Cno, Cname, Ccredit, Cpno)
课程号,课程名,学分,先修课程号
SC(Sno, Cno, Grade)
学号,课程号,成绩
所求问题:
查询平均成绩最高的学生学号,姓名和平均成绩?
小弟刚刚入门,道行不够,还请各位指点一下!
没多少分,先谢谢了!
------解决方案--------------------------------------------------------
select s.sno as sno,s.sname as sname avg(sc.grade) as avggrade from s,c,sc where s.sno=sc.sno and c.cno=sc.cno and s.sno=sc.sno group by s.sno order by avggrade
大概就是这样
------解决方案--------------------------------------------------------
select s.sno as sno,
s.sname as sname
avg(sc.grade) as avggrade
from s,c,sc
where s.sno=sc.sno and
c.cno=sc.cno and
s.sno=sc.sno and
avg(sc.grade) in (
select max(avg(sc.grade)) from sc group by sc.sno)