




已阅读5页,还剩17页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第五章作业 1 查询学生选课表中的全部数据select fromsc2 查询计算机系学生的姓名 年龄selectsname sagefromstudentwheresdept 计算机系 3 查询成绩在70 80的学生的学号 课程号和成绩select fromscwheregradebetween70to804 查询计算机系年龄在18 20的男生的姓名 年龄selectsname sagefromstudentWheresdept 计算机系 andsagebetween18to20andssex 男 5 查询 C01 课程的最高成绩Selectmax grade fromscwherecno c01 1 6 查询计算机系学生的最大年龄和最小年龄selectmax sage min sage fromstudentwheresdept 计算机系 7 统计每个系的学生人数selectsdept count fromstudentgroupbysdept8 统计每门课程的选课人数和考试最高分selectcno count max grade fromscgroupbycno9 统计每个学生的选课门数和考试总成绩 并按选课门数升序显示结果selectsno count sum grade fromscgroupbysnoorderbycount asc10 查询总成绩超过200分的学生 要求列出学号 总成绩selectsno sum grade fromscgroupbysnohavingsum grade 200 2 11 查询选修了 C02 课程的学生的姓名和所在系selectsname sdeptfromstudentsjoinscons sno sc snowheresc con c02 12 查询成绩80分以上的学生的姓名 选的课程号和成绩 并按成绩降序排列结果selectsname cno gradefromstudentsjoinscons sno sc snowheregrade 80orderbygradedesc13 查询哪些学生没有选课 要求列出学号 姓名和所在系selects sno sname sdeptfromstudentsleftjoinscons sno oisnull 3 14 查询与VB在同一学期开设的课程的课程名和开课学期ame c1 semesterfromcoursec1joincoursec2onc1 semester ame VB ame VB 15 查询与李勇年龄相同的学生的姓名 所在系和年龄selects2 sname s2 sdept s2 sagefromstudents1joinstudents2ons1 sage s2 sagewheres1 sname 李勇 ands2 sname 李勇 4 16 查询计算机系年龄最小的2名学生的姓名和年龄selecttop2withtiessname sagefromstudentwheresdept 计算机系 orderbysageasc17 查询VB考试成绩最高的前2名学生的姓名 所在系和VB成绩 包括并列的情况selecttop2withtiessname sdept gradefromstudentsjoinscons sno o owherecname VB orderbygradedesc18 查询选课门数最多的前2名学生的学号和选课门数 包括并列的情况selecttop2withtiessno count fromscgroupbysnoorderbycount desc19 查询学生人数最多的系 列出系名和人数 selecttop1sdept count fromstudentgroupbysdeptorderbycount desc 5 20 用子查询实现如下查询 1 查询选修了 C01 课程的学生姓名和所在系selectsname sdeptfromstudentwheresnoin selectsnofromscwherecon c01 2 查询数学系成绩80分以上的学生的学号 姓名 选的课程号和成绩selectsno sname cno gradefromstudentjoinsconstudent sno sc snowheresdept 数学系 andsnoin selectsnofromscwheregrade 80 6 20 3 查询计算机系考试成绩最高的学生的姓名selectsnamefromstudentsjoinscons sno sc snowheresdept 计算机系 andgrade selectmax grade fromscjoinstudentsons sno sc snowheresdept 计算机系 4 查询数据结构考试成绩最高的学生的姓名 所在系 性别和成绩selectsname sdept ssex gradefromstudentsjoinscons sno o owherecname 数据结构 andgrade selectmax grade o owherecname 数据结构 7 21 查询没有选修VB课程的学生的姓名和所在系selectsnamesdeptfromstudentsjoinscons sno o owherecname VB 22 查询计算机系没有选课的学生的姓名和所在系selectsnamefromstudentsleftjoinscons sno sc snoWheresdept 计算机系 oisnull 8 23 查询计算机系考试平均最低的学生的姓名以及所选的课程名selectsname cnamefromstudentsjoinscons sno o owheresdept 计算机系 andsno selecttop1snofromscorderbyave grade asc 9 24 查询1 5学期中选课人数最少的课程的课程名 开课学期和学分SELECTCname Semester CreditFROMCourseWHERE CnoIN SELECTTOP1WITHtiescnoFROMscGROUPBYcnoORDERBYCOUNT ASC AND SemesterBETWEEN1AND5 10 25 createtabletest t col1int col2char 10 notnull col3char 10 insertintotest t col2 values b1 insertintotest t col1 col2 col3 values 1 b2 c2 insertintotest t col1 col2 values 2 b3 11 26 删除考试成绩低于50分的学生的该门课程的选课记录deletefromscwheregrade60andsdept 计算机系 12 29 删除VB考试成绩最低的学生的VB选课记录deletefromscjoinstudentsons sno o owherecname vb andgrade selectmin grade fromscjoinstudentsonsc sno s snowherecname vb 13 30 将第2学期开设的所有课程的学分增加2分updatecoursesetcredit credit 2wheresemester 231 将VB课程的学分改为3分updatecoursesetcredit credit 2wherecname vb 32 将计算机系学生的年龄增加1岁updatestudentsetsage sage 1wheresdept 计算机系 14 33 将信息系学生的 计算机文化学 课程的考试成绩加5分updatescsetgrade grade 5wherecnoin selectcnofromcoursewherecname 计算机系 andsnoin selectsnofromstudentwheresdept 信息系 34 将选课人数最少的课程的学分降低1分updatecoursesetcredit credit 1wherecno selecttop1cnofromscgroupbycnoorderbycount asc 15 第六章作业 9 1 在student表上为sname列建立一个聚集索引 索引名为sldxcreateclusteredindexsldxonstudent sname 2 在course表上为cname列建立一个唯一的非聚集索引 索引名为cnidxcreateuniquenonclusteredindexcnidxoncourse cname 3 在SC表上为SNO和CNO建立一个组合的聚集索引 索引名为snocnoidxCreateclusteredindexsnocnoidxonsc sno cno 4 删除SNAME列上建立的sldx索引Dropindexsldx 16 12 1 查询学生的学号 姓名 所在系 课程名 课程号 课程学分createviewv1asselects sno sdept cno cname creditfromstudentsjoinscons sno o o2 查询学生的学号 姓名 选修的课程名和考试成绩createviewv2asselects sno sname cname gradefromstudentsjoinscons sno o o3 统计每个学生的选课门数 要求列出学生学号和选课门数createviewv3asselectsno count astotalfromscgroupbysno4 统计每个学生的选课总学分 要求列出学生学号和总学分 说明 考试成绩大于等于60分才能获得此门课程的学分 createviewv4asselectsno sum credit total o owheregrade 60groupbysno 17 13 1 查询考试成绩大于等于90分得学生的姓名 课程名和成绩selectsname cname gradefromv2wheregrade 902 查询选课门数超过3门的学生的学号和选课门数select fromv3wheretotal 33 查询计算机系选课门数超过3门的学生的姓名和选课门数selectsname totalfromv3joinstudentsonv3 sno s sno4 查询修课总学分超过10分的学生的学号 姓名 所在系和修课总学分selectv4 sno sname sdept total creditfromv4joinstudentsons sno v4 snowheretotal credit 105 查询年龄大于等于20的学生中 修课总学分超过10分的学生的姓名 年龄 所在系和修课总学分selectsname sage sdept total creditfromv4joinstudentsonv4 sno s snowheresage 20andtotal credit 10 18 14 修改视图v4 使其查询每个学生的学号 总学分和总的选课门数alterviewv4asselectsno sum credit count o ogroupbysno 19 第七章作业 6 关系模式 学生修课 学号 姓名 所在系 性别 课程号 课程名 学分 成绩 语义 一个学生可以选多门课程 一门课程可以被多名学生选 一个学生有唯一的所在系 每门课程有唯一的课程名和学分答 候选码为 学号 课程号 同时也是此关系模式的主键分解 学生表 学号 姓名 所在系 性别 课程表 课程号 课程名 学分 选课表 学号 课程号 成绩 20 7 关系模式 学生 学号 姓名 所在系 班号 班主任 系主任 语义 一个学生只在一个系的一个班学习 一个系只有一个系主任 一个班只有一名班主任 一个系可以有多个班 答 候选码为学号 同时
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论