数据库原理及应用习参题考答案.doc

  1. 1、本文档共11页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
数据库原理及应用习参题考答案

4-2 对于教务管理数据库的三个基本表 S(SNO,SNAME, SEX, AGE,SDEPT) SC(SNO,CNO,GRADE) C(CNO,CNAME,CDEPT,TNAME) 试用SQL的查询语句表达下列查询: ⑴ 检索LIU老师所授课程的课程号和课程名。 ⑵ 检索年龄大于23岁的男学生的学号和姓名。 ⑶ 检索学号为200915146的学生所学课程的课程名和任课教师名。 ⑷ 检索至少选修LIU老师所授课程中一门课程的女学生姓名。 ⑸ 检索WANG同学不学的课程的课程号。 ⑹ 检索至少选修两门课程的学生学号。 ⑺ 检索全部学生都选修的课程的课程号与课程名。 ⑻ 检索选修课程包含LIU老师所授课程的学生学号。 解: ⑴ select c#,cname from c where teacher=’liu’; ⑵ select s#,sname from s where age23 and sex=’m’; ⑶ select cname,teacher from sc,c where sc.c#=c.c# and s#=’200915146’ ⑷ select sname (连接查询方式) from s,sc,c where s.s#=sc.s# and sc.c#=c.c# and sex=’f’ and teacher=’liu’; 或: select sname (嵌套查询方式) from s where sex=’f’and s# in (select s# from sc where c# in (select c# from c where teacher=’liu’)) 或: select sname (存在量词方式) from s where sex=’f’ and exists(select* from sc where sc.s#=s.s# and exists(select * from c where c.c#=sc.c# and teacher=’liu’)) ⑸ select c# from c where not exists (select * from s,sc where s.s#=sc.s# and sc.c#=c.c# and sname=’wang)); ⑹ select distinct x.s# from sc as x,sc as y where x.s#=y.s# and x.c#!=y.c#; ⑺ select c#.cname from c where not exists (select * from s where not exists (select * from sc where s#=s.s# and c#=c.c#)); ⑻ select distinct s# from sc as x where not existis (select * from c where teacher=’liu’ and not exists (select * from sc as y where y.s#=x.s# and y.c#=c.c#)); 4-3 试用SQL查询语句表达下列对4.2题中教务管理数据库的三个基本表S、SC、C查询: ⑴ 统计有学生选修的课程门数。 ⑵ 求选修4号课程的学生的平均年龄。 ⑶ 求LIU老师所授课程的每门课程的学生平均成绩。 第 8 页 ⑷ 统计每门课程的学生选修人数(超过10人的课程才统计)。要求输出课程号和选修人数,查询结果按人数降序排列,若人数相同,按课程号升序排列。 ⑸ 检索学号比WANG同学大,而年龄比他小的学生姓名。 ⑹ 检索姓名以WANG打头的所有学生的姓名和年龄。 ⑺ 在SC中检索成绩为空值的学生学号和课程号。 ⑻ 求年龄大于女同学平均年龄的男学生姓名和年龄。 ⑼ 求年龄大于所有女同学年龄的男学生姓名和年龄。 解: ⑴ select count(distinct c#) from sc; ⑵ select avg(age) from s,sc where s.s#=sc.s# and c#=’4’and sex=’f’; ⑶ select c.c#,avg(grade) from sc,c where sc.c#=c.c# and teacher=’liu’; ⑷ select c#,count(s#) from sc group by c# having count(*)10 order by 2 desc,1; ⑸ select sname from s where s#all(select s# from s where sname=’w

文档评论(0)

3774384 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档