数据库实验五题目答案.doc

上传人:s****u 文档编号:12782155 上传时间:2020-05-24 格式:DOC 页数:12 大小:1.59MB
返回 下载 相关 举报
数据库实验五题目答案.doc_第1页
第1页 / 共12页
数据库实验五题目答案.doc_第2页
第2页 / 共12页
数据库实验五题目答案.doc_第3页
第3页 / 共12页
点击查看更多>>
资源描述
实验五实验5.1 数据查询1) 要求以School数据库为例,在该数据库中存在四张表格,分别为:l 表STUDENTS(sid, sname, email, grade);l 表TEACHERS(tid, tname, email, salary);l 表COURSES(cid, cname, hour);l 表CHOICES(no, sid, tid, cid, score)在数据库中,存在这样的关系:学生可以选择课程,一个课程对应一个教师。在表CHOICES中保存学生的选课记录。按以下要求对数据库进行查询操作:(1) 查询年级为2001的所有学生的名称并按编号升序排列。 程序:Select sname from students where grade=2001 order by sid asc; (2) 查询学生的选课成绩合格的课程成绩。 程序:Select score from choices where score59;(3) 查询课时是48或60的课程的名称。 程序:select cname from courses where hour=48or hour=60;(4) 查询所有课程名称中含有data的课程编号。 程序:select cid from courses where cname like%data%;(5) 查询所有选课记录的课程号(不重复显示)。 程序:select distinct cid from choices;(6) 统计所有教师的平均工资。 程序:select avg(salary) from teachers;(7) 查询所有教师的编号及选修其课程的学生的平均成绩,按平均成绩降序排列。程序:select tid,avg(score) from choices GROUP BY tid order by avg(score) desc;(8) 统计各个课程的选课人数和平均成绩。 程序:select count(distinct sid),avg(score)from choicesgroup by cid;(9) 查询至少选修了三门课程的学生编号。程序:select sid from choices group by sid having count(cid)=3;(10) 查询编号800009026的学生所选的全部课程的课程名和成绩。程序:select distinct cname ,score from courses,choices where sid=800009026and courses.cid=choices.cid(11) 查询所有选修了database的学生的编号。程序:select sid from choices ,courses where cname=databaseand choices.cid=courses.cid;(12) 求出选择了同一个课程的学生对。 程序:Select x.sid,y.sid From choices x,choices y Where x.cid=y.cid and x.sidy.sid (13) 求出至少被两名学生选修的课程编号。 程序:select cid from choices group by cid having count(sid)=2;(14) 查询选修了编号800009026的学生所选的某个课程的学生编号。 程序:select sid from choices where cid in (select cid from choices where sid=800009026)and sid800009026;(15) 查询学生的基本信息及选修课程编号和成绩。 程序:select students.sid,sname,email,grade,cid,score from students,choices where students.sid=choices.sid;(16) 查询学号850955252的学生的姓名和选修的课程名及成绩。 程序:select sname,cname,score from students,courses,choices where choices.sid=850955252and students.sid=choices.sid and courses.cid=choices.cid; (17) 查询与学号850955252的学生同年级的所有学生资料。 程序:select * from students where grade=(select grade from students where sid=850955252);(18) 查询所有有选课的学生的详细信息。 程序:select students.sid,sname,email,grade,no ,cid,score from students,choices where cid is not null and students.sid=choices.sid;
展开阅读全文
相关资源
相关搜索

当前位置:首页 > 图纸专区 > 考试试卷


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!