补充作业答案

学籍管理系统数据库中的表。表Student_course,Student,Course ,Tearch_course和Teacher 。各个表的具体结构如下:

表1 student表(学生信息表)

1 简单查询操作

对EDUC 数据库实现以下查询: (1)求计算机系的学生学号和姓名;

select sno, sname from student

where sdept='IS'

(2)求选修C1 课程的学生学号和成绩,并要求对查询结果按成绩的降序排列,如果成绩相同则按学号的升序排列; select sno,score from student_course where cno='101'

ORDER BY score DESC,sno

(3)求选修课程C1 且成绩在80-90 之间的学生学号和成绩,并将成绩乘以系数0.75 输出;

select sno,score*0.75 from student_course

where cno='101' AND (score=80)

(4)求计算机系和数学系的姓张的学生的信息; SELECT *

FROM student

where (sdept='CS' OR sdept='MS' )AND sname LIKE '张%'

(5)求缺少了成绩的学生的学号和课程号。 SELECT sno,cno

FROM student_course where score IS NULL

(6)将成绩大于90分的学生成绩存入永久成绩表;将成绩小于90存入临时成绩表中。

SELECT score into prescore FROM student_course where score >90

SELECT score into #posscore FROM student_course where score

2 连接查询操作

对EDUC 数据库实现以下查询:

(1)查询每个学生的情况以及他(她)所选修的课程;

SELECT student.*,student_course.* FROM student, student_course

where student_course. sno =student . sno

(2)求学生的学号、姓名、选修的课程名及成绩;

SELECT student.sno,sname,course.cname,student_course.score FROM student,course,student_course

where student_course.sno=student.sno and student_course.cno= course.cno

(3)求选修C1 课程且成绩在90 分以上的学生学号、姓名及成绩; SELECT student.sno,sname,score FROM student, student_course

WHERE cno='102' AND score>90 and student_course.sno=student.sno

(4)查询每一门课的间接先行课。

SELECT first. cno , second . spno FROM course first, course second

WHERE first. spno = second. cno and second. spno is not NULL

3.子查询操作,在数据库EDUC 中实现查询: (1)求选修了高等数学的学生学号和姓名;

SELECT sno,sname from student

where sno in (SELECT sno from student_course

where cno in ( SELECT cno from course

where cname='高等数学'))

SELECT student.sno,sname

from student,course,student_course

where student.sno=student_course.sno AND student_course.cno=course.cno

AND course.cname='高等数学'

(2)求C1 课程的成绩高于张三的学生学号和成绩;

SELECT sno, score from student_course

where cno = '101' AND score > SOME ( SELECT score from student_course

where cno ='101' and sno in( SELECT sno from student

where sname=' 张楠' ))

(3)求其他系中比计算机系某一学生年龄小的学生信息(即求其它系中年龄小于计算机系年龄最大者的学生);some(any)均可以

SELECT * FROM student

where sdept != 'CS' and sage

(4)求其他系中比计算机系学生年龄都小的学生信息; SELECT * FROM student

where sdept != 'CS' and sage

(5)求选修了select sname

from student

where sno in (select sno from student_course where cno='102' )

C2 课程的学生姓名;

(6)求没有选修C2 课程的学生姓名;

select sname

from student

where sno not in (select sno from student_course where cno='102' )

(7)查询选修了全部课程的学生的姓名;

select sname from student

where sno in (select sno from student_course where cno is not null)

(8)求至少选修了学号为“1103”的学生所选修的全部课程的学生学号和姓名。

select sno, sname from student where sno in ( select sno

from student_course where cno in (select cno

from student_course where sno= '1103' ))

4.使用子句的查询操作,在数据库EDUC 中实现查询: (1) 求学生的总人数。

SELECT count(sno) FROM studen

(2) 求选修了课程的学生人数。

SELECT count (distinct sno) FROM student_course

(3) 求课程的课程号和选修该课程的人数。

SELECT cno,count (sno )

FROM student_course Group by cno

(4) 求选修课超过3 门课的学生学号

SELECT sno

FROM student_course

Group by sno having count (cno )>=3

学籍管理系统数据库中的表。表Student_course,Student,Course ,Tearch_course和Teacher 。各个表的具体结构如下:

表1 student表(学生信息表)

1 简单查询操作

对EDUC 数据库实现以下查询: (1)求计算机系的学生学号和姓名;

select sno, sname from student

where sdept='IS'

(2)求选修C1 课程的学生学号和成绩,并要求对查询结果按成绩的降序排列,如果成绩相同则按学号的升序排列; select sno,score from student_course where cno='101'

ORDER BY score DESC,sno

(3)求选修课程C1 且成绩在80-90 之间的学生学号和成绩,并将成绩乘以系数0.75 输出;

select sno,score*0.75 from student_course

where cno='101' AND (score=80)

(4)求计算机系和数学系的姓张的学生的信息; SELECT *

FROM student

where (sdept='CS' OR sdept='MS' )AND sname LIKE '张%'

(5)求缺少了成绩的学生的学号和课程号。 SELECT sno,cno

FROM student_course where score IS NULL

(6)将成绩大于90分的学生成绩存入永久成绩表;将成绩小于90存入临时成绩表中。

SELECT score into prescore FROM student_course where score >90

SELECT score into #posscore FROM student_course where score

2 连接查询操作

对EDUC 数据库实现以下查询:

(1)查询每个学生的情况以及他(她)所选修的课程;

SELECT student.*,student_course.* FROM student, student_course

where student_course. sno =student . sno

(2)求学生的学号、姓名、选修的课程名及成绩;

SELECT student.sno,sname,course.cname,student_course.score FROM student,course,student_course

where student_course.sno=student.sno and student_course.cno= course.cno

(3)求选修C1 课程且成绩在90 分以上的学生学号、姓名及成绩; SELECT student.sno,sname,score FROM student, student_course

WHERE cno='102' AND score>90 and student_course.sno=student.sno

(4)查询每一门课的间接先行课。

SELECT first. cno , second . spno FROM course first, course second

WHERE first. spno = second. cno and second. spno is not NULL

3.子查询操作,在数据库EDUC 中实现查询: (1)求选修了高等数学的学生学号和姓名;

SELECT sno,sname from student

where sno in (SELECT sno from student_course

where cno in ( SELECT cno from course

where cname='高等数学'))

SELECT student.sno,sname

from student,course,student_course

where student.sno=student_course.sno AND student_course.cno=course.cno

AND course.cname='高等数学'

(2)求C1 课程的成绩高于张三的学生学号和成绩;

SELECT sno, score from student_course

where cno = '101' AND score > SOME ( SELECT score from student_course

where cno ='101' and sno in( SELECT sno from student

where sname=' 张楠' ))

(3)求其他系中比计算机系某一学生年龄小的学生信息(即求其它系中年龄小于计算机系年龄最大者的学生);some(any)均可以

SELECT * FROM student

where sdept != 'CS' and sage

(4)求其他系中比计算机系学生年龄都小的学生信息; SELECT * FROM student

where sdept != 'CS' and sage

(5)求选修了select sname

from student

where sno in (select sno from student_course where cno='102' )

C2 课程的学生姓名;

(6)求没有选修C2 课程的学生姓名;

select sname

from student

where sno not in (select sno from student_course where cno='102' )

(7)查询选修了全部课程的学生的姓名;

select sname from student

where sno in (select sno from student_course where cno is not null)

(8)求至少选修了学号为“1103”的学生所选修的全部课程的学生学号和姓名。

select sno, sname from student where sno in ( select sno

from student_course where cno in (select cno

from student_course where sno= '1103' ))

4.使用子句的查询操作,在数据库EDUC 中实现查询: (1) 求学生的总人数。

SELECT count(sno) FROM studen

(2) 求选修了课程的学生人数。

SELECT count (distinct sno) FROM student_course

(3) 求课程的课程号和选修该课程的人数。

SELECT cno,count (sno )

FROM student_course Group by cno

(4) 求选修课超过3 门课的学生学号

SELECT sno

FROM student_course

Group by sno having count (cno )>=3


相关内容

  • 山东建筑大学会计学补充作业--第四章.答案
  • 补充题:燕山公司2009年12月31日有关损益类账户余额如下(单位为元):主营业务收入2 000 000,其他业务收入29 000,营业外收入100000,主营业务成本500000,其他业务成本17 000,营业税金及附加100000, 销售费用50000,管理费用150000,营业外支出6 000 ...

  • 比值控制系统补充作业答案
  • (1) 三种结构不同的比值控制系统如下图所示,试绘制其系统方框图,分析它们的优缺 点. (2) 如果某系统采用的是4-20mA 信号,比值K=Q2/Q1=3,Q 2max =6×103kg/h,Q 1max =2 ×103kg/h,流量测量时不加开方器,试求出其比值系数K',如果该系统采用图(a ) ...

  • 机电管理实务案例
  • 机电管理实务案例 1 机电工程项目施工组织设计 一. 机电工程项目施工组织设计 案例1 某石油化工装置进行工程招标, 某一施工单位根据招标方提供的实物量清单进行投标, 并中标.签订工程合同后, 由于工程急于开工, 该施工单位在未收到施工图纸的情况下, 即进行了施工组织设计的编制, 施工单位在原投标书 ...

  • 2013年一建建筑实务真题
  • 一.单项选择题(共20 题,每题1 分.每题的备选项中,只有一个最符合题意) 1 .设计使用年限50年的普通住宅工程,其结构混凝土的强度等级不应低于( ). A . C20 B . C25 C. C30 D.C35 [答案」B [解析] 设计年限为50 年的建筑物,其混凝土强度等级不应低干C25.参 ...

  • 20156英语教研组工作小结
  • 探究教学新体系,提高英语课堂实效 ----2014学年度第二学期工作小结 天山初中英语教研组 转眼间,一学期的工作即将结束,在学校的领导下,关心.指导下,在每一位英语教师的努力下,坚持以人为本,倡导创新精神.在组员们大力支持下,我们顺利完成了各项教学研修任务.由于本学期时间短,任务重,所以是紧张繁忙 ...

  • 2011年寒假八年级语文[假期作业]部分答案及补充
  • 2011年寒假八年级语文<假期作业>部分答案及补充 [第一组] (一)我的小学 贾平凹 五岁那年,娘牵着我去报名,学校里不收,我就抱住报名室的桌子腿哭,老师都围着我笑:最后就收下了,但不是正式学生,是一年级就买了这糖,让开学后发给我们每人一颗.我们就都哭了.从那以后,我再也没有见到我的那 ...

  • 经济师考试初级人力资源模拟练习题(6)
  • 2012 年经济师考试初级人力资源模拟练习题 (六)一.单项选择题: 1. 概括化的经验系统是指( ). A.技能 B.能力 C.情绪 D.知识 [答案]:D 2. 包括对自我的控制.自信和工作中的灵活性是一个优秀的领导者应该具备的( )能力. A.服务意识 B.认知能力 C.管理才能 D.个人效能 ...

  • [尔雅通识课]选课与学习指南
  • <尔雅通识课>选课与学习指南 为了让我校学生也能听到来自国内名校名师的名课,获取更多课程知识以开拓视野,从上学期开始,学校引进"尔雅通识课"作为全校公选课的一种补充供全校学生选修,学习方式为网络自主学习,在完成课程规定内容的学习后,通过在线考试即可获得公选课学分.学生 ...

  • 苏教版小学语文六年级试卷大全
  • 1. 小学语文六年级上册期末复习资料汇总 2. 六年级语文上册知识点归类 3. 六年级语文上册各类试题知识点汇总 4. 六年级语文上册课后习题知识点汇总 5. 小学语文六年级下册第6周周练试卷 6. 小学语文六年级下册第3周周练试卷 7. 小学语文六年级下册第14周周练试卷 8. 小学语文六年级下册 ...