博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
数据库练习题26-45题
阅读量:4346 次
发布时间:2019-06-07

本文共 3436 字,大约阅读时间需要 11 分钟。

1 --26、  查询存在有85分以上成绩的课程Cno. 2 select distinct Cno from Score where Degree >85 3  4 --27、查询出“计算机系“教师所教课程的成绩表。 5 select * from Score where Cno in ( select Cno from Course where Tno in ( select Tno from Teacher where Depart = '计算机系')) 6  7  8 --0028、查询“计算机系”与“电子工程系“不同职称的教师的Tname和Prof。 9 select Tname,Prof from Teacher t1 where Depart = '计算机系' and not exists (select * from Teacher t2 where Depart = '电子工程系' and t1.Prof = t2.prof)10 union11 select Tname,Prof from Teacher t1 where Depart = '电子工程系' and not exists (select * from Teacher t2 where Depart = '计算机系' and t1.Prof = t2.prof)12 13 --0029、查询选修编号为“3-105“课程且成绩至少高于一个选修编号为“3-245”的同学的Cno、Sno和Degree,并按Degree从高到低次序排序。--any 任何一个值 , all 所有的数值14 select * from Score where Degree >any( select Degree from Score where Cno='3-245') and Cno ='3-105'  order by  Degree desc15 16 --30、查询选修编号为“3-105”且成绩高于选修编号为“3-245”课程的同学的Cno、Sno和Degree.17 select * from Score where Degree > all(select Degree from Score where Cno='3-245') and Cno='3-105' 18 19 --31、 查询所有教师和同学的name、sex和birthday.20     select Sname,Ssex,Sbirthday from Student21 union22     select Tname,Tsex,Tbirthday from Teacher23 24 --32、查询所有“女”教师和“女”同学的name、sex和birthday.25     select Sname,Ssex,Sbirthday from Student where Ssex='女'26 union27     select Tname,Tsex,Tbirthday from Teacher where Tsex='女'28 29 --33、 查询成绩比该课程平均成绩低的同学的成绩表。30     select * from Score s1 where Degree<(select AVG(degree) from Score s2 group by Cno having s1.Cno= s2.Cno)31 32 --34、 查询所有任课教师的Tname和Depart.33     select Tname,Depart from Teacher where Tno in ( select Tno from Course where Cno in (select Cno from Score))34 35 --35 、 查询所有未讲课的教师的Tname和Depart. 36     select Tname,Depart from Teacher where Tno not in ( select Tno from Course where Cno in (select Cno from Score))37 38 --36、查询至少有2名男生的班号。--先选出所有男生,再按班级分组39     select Class from Student where Ssex='男' group by Class having COUNT(*)>140 41 --37、查询Student表中不姓“王”的同学记录。  42     select * from Student where Sname not like '王%'43 44 --0038、查询Student表中每个学生的姓名和年龄。45      --注:year(getdate())获取当前时间“年” getdate()获取46     select Sname,year(getdate())-YEAR(Sbirthday) as age from Student 47 48 --39、查询Student表中最大和最小的Sbirthday日期值。49      select MAX(Sbirthday),MIN(Sbirthday) from Student50 51 --40、以班号和年龄从大到小的顺序查询Student表中的全部记录。52     select  *  from Student  order by Class desc,Sbirthday asc53  54 --41、查询“男”教师及其所上的课程。55     select Cname,Tname from Course join Teacher on Course.Tno=Teacher.Tno where Tsex='男' --联合2个表格做法56     57 select * from course where tno in(select tno from teacher where tsex='男')    --where做法58 59 --42、查询最高分同学的Sno、Cno和Degree列。60     select Sno,Cno,Degree from Score where Degree =( select MAX(Degree) from Score )--方法一61 62     select top 1 * from score order by degree desc     --方法二63 64 --43、查询和“李军”同性别的所有同学的Sname.65     select Sname from Student where Ssex=( select Ssex from Student  where Sname='李军') and Sname !='李军'66 67 --44、查询和“李军”同性别并同班的同学Sname.68     select Sname from Student where Ssex=( select Ssex from Student  where Sname='李军') and Class=(select Class from Student where Sname='李军') and Sname !='李军' --方法一69 70 select sname from student s1 where ssex=(71 select ssex from student s2 where sname='李军' and s1.class= s2.class72 )--方法二    73 74 --45、查询所有选修“计算机导论”课程的“男”同学的成绩表。75     select * from Score where Cno=( select Cno from Course where Cname='计算机导论') and Sno in (select Sno from Student where Ssex='男')--f方法1

 

转载于:https://www.cnblogs.com/franky2015/p/4665563.html

你可能感兴趣的文章
解决VS2015安装Android SDK 后文件不全及更新问题
查看>>
辣鸡咯..
查看>>
(2018干货系列一)最新Java学习路线整合
查看>>
django 快速搭建blog
查看>>
Chrome插件:本地程序实现验证码破解(浏览器与本地进程通信)
查看>>
学习的态度!
查看>>
小组成员名单()
查看>>
[Javascirpt] What’s new in JavaScript (Google I/O ’19)
查看>>
[Angular 2] Writing a Simple Angular 2 Component
查看>>
可能会用的到的JQ插件
查看>>
高斯消元模板
查看>>
【GPS】SAP测试GPS模块拿不到sensor数据
查看>>
python 数据类型之列表、元组、字典、集合
查看>>
【Java并发编程】8、各种锁的概念
查看>>
【Java基础】5、java中的匿名内部类
查看>>
Python中capitalize()与title()的区别
查看>>
GRASP (职责分配原则)
查看>>
C#语言特性-运算符重载
查看>>
echart.js的使用
查看>>
IC 设计中DFT的Boundary Scan功能
查看>>