数据库练习题26-45题
2015-07-21 20:38
316 查看
--26、 查询存在有85分以上成绩的课程Cno. select distinct Cno from Score where Degree >85 --27、查询出“计算机系“教师所教课程的成绩表。 select * from Score where Cno in ( select Cno from Course where Tno in ( select Tno from Teacher where Depart = '计算机系')) --0028、查询“计算机系”与“电子工程系“不同职称的教师的Tname和Prof。 select Tname,Prof from Teacher t1 where Depart = '计算机系' and not exists (select * from Teacher t2 where Depart = '电子工程系' and t1.Prof = t2.prof) union select Tname,Prof from Teacher t1 where Depart = '电子工程系' and not exists (select * from Teacher t2 where Depart = '计算机系' and t1.Prof = t2.prof) --0029、查询选修编号为“3-105“课程且成绩至少高于一个选修编号为“3-245”的同学的Cno、Sno和Degree,并按Degree从高到低次序排序。--any 任何一个值 , all 所有的数值 select * from Score where Degree >any( select Degree from Score where Cno='3-245') and Cno ='3-105' order by Degree desc --30、查询选修编号为“3-105”且成绩高于选修编号为“3-245”课程的同学的Cno、Sno和Degree. select * from Score where Degree > all(select Degree from Score where Cno='3-245') and Cno='3-105' --31、 查询所有教师和同学的name、sex和birthday. select Sname,Ssex,Sbirthday from Student union select Tname,Tsex,Tbirthday from Teacher --32、查询所有“女”教师和“女”同学的name、sex和birthday. select Sname,Ssex,Sbirthday from Student where Ssex='女' union select Tname,Tsex,Tbirthday from Teacher where Tsex='女' --33、 查询成绩比该课程平均成绩低的同学的成绩表。 select * from Score s1 where Degree<(select AVG(degree) from Score s2 group by Cno having s1.Cno= s2.Cno) --34、 查询所有任课教师的Tname和Depart. select Tname,Depart from Teacher where Tno in ( select Tno from Course where Cno in (select Cno from Score)) --35 、 查询所有未讲课的教师的Tname和Depart. select Tname,Depart from Teacher where Tno not in ( select Tno from Course where Cno in (select Cno from Score)) --36、查询至少有2名男生的班号。--先选出所有男生,再按班级分组 select Class from Student where Ssex='男' group by Class having COUNT(*)>1 --37、查询Student表中不姓“王”的同学记录。 select * from Student where Sname not like '王%' --0038、查询Student表中每个学生的姓名和年龄。 --注:year(getdate())获取当前时间“年” getdate()获取 select Sname,year(getdate())-YEAR(Sbirthday) as age from Student --39、查询Student表中最大和最小的Sbirthday日期值。 select MAX(Sbirthday),MIN(Sbirthday) from Student --40、以班号和年龄从大到小的顺序查询Student表中的全部记录。 select * from Student order by Class desc,Sbirthday asc --41、查询“男”教师及其所上的课程。 select Cname,Tname from Course join Teacher on Course.Tno=Teacher.Tno where Tsex='男' --联合2个表格做法 select * from course where tno in(select tno from teacher where tsex='男') --where做法 --42、查询最高分同学的Sno、Cno和Degree列。 select Sno,Cno,Degree from Score where Degree =( select MAX(Degree) from Score )--方法一 select top 1 * from score order by degree desc --方法二 --43、查询和“李军”同性别的所有同学的Sname. select Sname from Student where Ssex=( select Ssex from Student where Sname='李军') and Sname !='李军' --44、查询和“李军”同性别并同班的同学Sname. select Sname from Student where Ssex=( select Ssex from Student where Sname='李军') and Class=(select Class from Student where Sname='李军') and Sname !='李军' --方法一 select sname from student s1 where ssex=( select ssex from student s2 where sname='李军' and s1.class= s2.class )--方法二 --45、查询所有选修“计算机导论”课程的“男”同学的成绩表。 select * from Score where Cno=( select Cno from Course where Cname='计算机导论') and Sno in (select Sno from Student where Ssex='男')--f方法1
相关文章推荐
- mysql的远程监控,可以知道mysql的运行情况
- 数据库练习题1-25题
- Redis缓存
- oracle 高级队列
- 数据库连接,会话,事务
- SQL————高级查询
- 7.19 SQL——函数
- Redis基本认识
- Mysql数据库笔记
- Ubuntu mysql 中文,启动,重启,远程连接相关问题
- windows下安装php5.5的redis扩展
- mysql的having语句
- sql 中的时间处理问题
- Redis能干啥?细看11种Web应用场景
- 几点建议,让Redis在你的系统中发挥更大作用
- windows程序设计——飞机大战笔记(调用登陆数据库)
- mysql分表的3种方法
- php windows 扩展redis
- 关于mysql主从复制error_code 1593的小异常BUG
- MySQL INTO OUTFILE导出导入数据|mysqldump