当前位置: 代码迷 >> DB2 >> 简单sql查询语句
  详细解决方案

简单sql查询语句

热度:4943   发布时间:2013-02-26 00:00:00.0
求一个简单sql查询语句?
现有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)
  相关解决方案