查询选修c语言课程的学生学号和姓名,数据库嵌套循环查询联系——1.查询选修了课程号为“3”的学生姓名和系别、4.查询其它系中‘2‘号课程比信息系所有学生分数高的学生学号和姓名、6.查询每门课程中低于该...

2655137282a37c7ffe5f52cc836f1dbe.png

1.查询选修了课程号为“3”的学生姓名和系别

Select sname,sdept from student where sno in (

select sno from sc where cno=‘3’);

2.查询与“刘一平”来自同一个系的学生姓名

Select sname from student where sdept in (

select sdept from student where sname=‘刘晨’) and sname <> ‘刘晨’;

3.查询Sc表中的最高分的学生学号和课程号

select sno,cno from sc where grade in(

select max(grade) from sc);

另一种:

select sno,cno from sc where grade >=all(

select grade from sc);

4.查询其它系中‘2‘号课程比信息系所有学生分数高的学生学号和姓名;

select distinct student.sno,sname from student,sc where student.sno=sc.sno and cno=‘2’ and grade >all (

select grade from sc where sdept=‘is’ ) and sdept <> ‘is’;

改进:

select distinct student.sno,sname from student,sc where student.sno=sc.sno and cno=‘2’ and grade >all ( select grade from sc where sno in(select sno from student where sdept = ‘is’) ) and sdept <> ‘is’;

老师:

select sno,sname from student where sno in (select sno from sc where cno=‘2’ and sno not in(select sno from student where sdept=‘cs’) and grade>(select max(grade) from sc where cno=‘2’ and sno in(select sno from student where sdept=‘cs’)));

5.查询其它系中比信息系所有学生年龄大的学生姓名和性别;

Select distinct sname,ssex from student where sage >all (

select sage from student where sdept = ‘is’ ) and sdept <> ‘is’;

6.查询每门课程中低于该课程平均成绩的学生学号和姓名;

Select student.sno,sname from student,sc x where student.sno = x.sno and grade < (

select avg(grade) from sc y where y.cno=x.cno ) ;

7.查询“信息系”中选课最多的学生学号;

select student.sno from student,sc where sc.sno=student.sno and student.sdept=‘is’ group by sc.sno having count() >= all(

select count() from sc, student where sc.sno= student.sno and sdept=‘is’ group by sc.sno);

select sno from student where sdept=‘cs’ and sno in(select sno from sc group by sno having count()>=all(select count() from sc where sno in(select sno from student where sdept=‘cs’)group by sno));

8.查询所有选修“计算机导论”课程的“男”同学的成绩表

select student.sno,sname,course.cno,cname,grade from student,sc,course where student.sno=sc.sno and course.cno=sc.cno and ssex=‘男’ and student.sno in(select sno from sc,course where sc.cno=course.cno and cname = ‘计算机导论’);

af26055919cd1c9e12881e6fc3ded796.png

9.查询有两门及以上课程不及格的学生学号和姓名;

14da007e7a34f6ac322cb0a6b8833523.png

10.查询比“2”号课程平均分高的其它课程信息;

15495e74ec74ed6c4d835472ac2509ac.png

  • 6
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值