首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

关于多表查询的有关问题

2012-01-15 
关于多表查询的问题!首先有3个表:1、student表,字段sno,sname,sex,height2、coures表,字段cno,cname,credit(

关于多表查询的问题!
首先有3个表:  
1、student表,字段sno,sname,sex,height  
2、coures表,字段cno,cname,credit(学分?)  
3、sc表,字段sno,cno,grade(得分?)  

问题:  
1、查询每个学生的平均成绩  
2、给出所有超过5个学生选的课程  
3、按总平均值降序给出所有课程均及格但不包括课程代号为C8的所有学生总平均值


谢谢

[解决办法]
1
不带姓名
select sno, avg(grade) grade from sc group by sno
带姓名
select a.sno,a.sname,b.grade student a,
(select sno, avg(grade) grade from sc group by sno) b
where a.sno = b.sno
[解决办法]
2
select * from oures where cno in
(select cno from sc group by cno having count(*) > 5 )

热点排行