补充作业答案
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
学籍管理系统数据库中的表。表Student_course,Student , Course, Tearch_course和Teacher。各个表的具体结构如下:
表1 stude nt 表(学生信息表)
class no char 4 NULL 班级号
eno char 10 NOT NULL 课程编号(外键)
semester char 6 NULL 学期
schoolyear char 10 NULL 学年
classtime varchar 40 NULL 上课时间
classroom varchar 40 NULL 上课地点
weektime tin yi nt 1 NULL 每周课时数
1简单查询操作
对EDU(数据库实现以下查询:
(1)求计算机系的学生学号和姓名;
select sno , sname
from stude nt
where sdept ='IS'
(2) 求选修C1课程的学生学号和成绩,并要求对查询结果按成绩的降序排
列,如果成绩相同则按学号的升序排列;
select sno ,score
from stude nt_course
where cn o='101'
ORDER BY score DESC,s no
(3) 求选修课程C1且成绩在80- 90之间的学生学号和成绩,并将成绩乘
以系数0.75输出;
select sno ,score*0.75
from stude nt_course
where cn o='101' AND (score<=90 AND score>=80)
(4) 求计算机系和数学系的姓张的学生的信息;
SELECT *
FROM stude nt
where (sdept='CS' OR sdept='MS' )AND sn ame LIKE 张%'
(5) 求缺少了成绩的学生的学号和课程号。
SELECT sno,cno
FROM stude nt_course
where score IS NULL
(6) 将成绩大于90分的学生成绩存入永久成绩表;将成绩小于90存入临时
成绩表中。
SELECT score into prescore FROM stude nt_course where score >90
SELECT score into #posscore
FROM stude nt_course
where score <90
2连接查询操作
对EDU(数据库实现以下查询:
(1)查询每个学生的情况以及他(她)所选修的课程;
SELECT stude nt .*, stude nt_course .*
FROM student , student_course
where student_course . sno =student . sno
(2)求学生的学号、姓名、选修的课程名及成绩;
SELECT stude nt.s no,s name,course.c name,stude nt_course.score
FROM stude nt,course,stude nt_course
where stude nt_course.s no=stude nt.s no and stude nt_course.c no= course.c no (3)求选修C1课程且成绩在90分以上的学生学号、姓名及成绩;
SELECT stude nt.s no,sn ame,score
FROM stude nt, stude nt_course
WHERE cn o='102' AND score>90 and stude nt_course.s no=stude nt.s no (4)查询每一门课的间接先行课。一
SELECT first . eno , second . spno
FROM course first , course second
WHEREfirst . spno = second . eno and second . spno is not NULL
3. 子查询操作,在数据库EDU(中实现查询:
(1)求选修了高等数学的学生学号和姓名;
SELECT sno,sn ame
from stude nt
where sno in (SELECT sno
from stude nt_course
where eno in ( SELECT eno
from course
where cname='高等数学'))
SELECT stude nt.s no,sn ame
from stude nt,course,stude nt_course
where stude nt.s no=stude nt_course.s no AND stude nt_course.c no=course.c no
AND course.c name='高等数学
(2) 求C1课程的成绩高于张三的学生学号和成绩;
SELECT sno , score
from stude nt_course
where eno = '101' AND score > SOME(
SELECT score
from stude nt_course
where eno ='101' and sno in(
SELECT sno
from stude nt
where sname ='张楠'))
(3 )求其他系中比计算机系某一学生年龄小的学生信息(即求其它系中年龄小
于计算机系年龄最大者的学生);some(any)均可以
SELECT *
FROM stude nt where sdept != 'CS' and sage where sdept ='CS' ) (4)求其他系中比计算机系学生年龄都小的学生信息; SELECT * FROM stude nt where sdept != 'CS' and sage from stude nt where sdept ='CS' ) (5)求选修了C2课程的学生姓名; select sn ame from stude nt where sno in (select sno from stude nt_course where eno ='102' ) (6)求没有选修C2课程的学生姓名; select sn ame from stude nt where sno not in ( select sno from student_course where eno ='102' ) (7)查询选修了全部课程的学生的姓名; select sn ame from stude nt where sno in ( select sno from student_course where eno is not null) (8)求至少选修了学号为“ 1103”的学生所选修的全部课程的学生学号和姓 名。 select sno , sname from stude nt where sno in ( select sno from stude nt_course where eno in (select eno from stude nt_course