数据库第五六七章作业答案

上传人:仙*** 文档编号:245081296 上传时间:2024-10-07 格式:PPT 页数:22 大小:256.99KB
返回 下载 相关 举报
数据库第五六七章作业答案_第1页
第1页 / 共22页
数据库第五六七章作业答案_第2页
第2页 / 共22页
数据库第五六七章作业答案_第3页
第3页 / 共22页
点击查看更多>>
资源描述
单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,*,第五章作业,1,、查询学生选课表中的全部数据,select *from sc,2,、查询计算机系学生的姓名、年龄,select sname,sage from student,where sdept=,计算机系,3,、查询成绩在,70-80,的学生的学号、课程号和成绩,select*from sc where grade between 70 to 80,4,、查询计算机系年龄在,18-20,的男生的姓名、年龄,select sname,sage from student,Where sdept=,计算机系,and sage between 18 to 20 and ssex=,男,5,、查询“,C01”,课程的最高成绩,Select max(grade)from sc where cno=c01,6,、查询计算机系学生的最大年龄和最小年龄,select max(sage),min(sage)from student,where sdept=,计算机系,7,、统计每个系的学生人数,select sdept,count(*)from student group by sdept,8,、统计每门课程的选课人数和考试最高分,select cno,count(*),max(grade)from sc group by cno,9,、统计每个学生的选课门数和考试总成绩,并按选课门数升序显示结果,select sno,count(*),sum(grade)from sc,group by sno order by count(*)asc,10,、查询总成绩超过,200,分的学生,要求列出学号、总成绩,select sno,sum(grade)from sc,group by sno having sum(grade)200,11,、查询选修了”,C02“,课程的学生的姓名和所在系,select sname,sdept from student s join sc on s.sno=sc.sno where sc.con=c02,12,、查询成绩,80,分以上的学生的姓名、选的课程号和成绩,并按成绩降序排列结果,select sname,cno,grade from student s join sc,on s.sno=sc.sno where grade 80 order by grade desc,13,、查询哪些学生没有选课,要求列出学号、姓名和所在系,select s.sno,sname,sdept from student s left join sc on,s.sno=sc.sno where o is null,14,、查询与,VB,在同一学期开设的课程的课程名和开课学期,select ame,c1.semester from course c1 join course c2 on c1.semester=c2.semester where ame=VBand ame!=VB,15,、查询与李勇年龄相同的学生的姓名、所在系和年龄,select s2.sname,s2.sdept,s2.sage from student s1 join student s2 on s1.sage=s2.sage where s1.sname=,李勇,and s2.sname!=,李勇,16,、查询计算机系年龄最小的,2,名学生的姓名和年龄,select top 2 with ties sname,sage from student where sdept=,计算机系,order by sage asc,17,、查询,VB,考试成绩最高的前,2,名学生的姓名、所在系和,VB,成绩,包括并列的情况,select top 2 with ties sname,sdept,grade from student s join sc on s.sno=sc.sno join course c on o=o where cname=VB order by grade desc,18,、查询选课门数最多的前,2,名学生的学号和选课门数,包括并列的情况,select top 2 with ties sno,count(*)from sc,group by sno order by count(*)desc,19,、查询学生人数最多的系,列出系名和人数。,select top 1 sdept,count(*)from student,group by sdept order by count(*)desc,20,、用子查询实现如下查询:,1,)查询选修了”,C01“,课程的学生姓名和所在系,select sname,sdept from student,where sno in(select sno from sc where con=c01),2,)查询数学系成绩,80,分以上的学生的学号、姓名、选的课程号和成绩,select sno,sname,cno,grade from student join sc,on student.sno=sc.sno where sdept=,数学系,and sno in(select sno from sc where grade80),20,、,3,)查询计算机系考试成绩最高的学生的姓名,select sname from student s join sc on s.sno=sc.sno where sdept=,计算机系,and,grade=(select max(grade)from sc join student s on s.sno=sc.sno where sdept=,计算机系,),4,)查询数据结构考试成绩最高的学生的姓名、所在系、性别和成绩,select sname,sdept,ssex,grade from student s join sc on s.sno=sc.sno join course on o=o where cname=,数据结构,and grade=(select max(grade)from sc join count on o=o where cname=,数据结构,),21,、查询没有选修,VB,课程的学生的姓名和所在系,select sname sdept from student s join sc on s.sno=sc.sno join course c on o=o where cname!=VB,22,、查询计算机系没有选课的学生的姓名和所在系,select sname from student s left join sc on s.sno=sc.sno Where sdept=,计算机系,and o is null,23,、查询计算机系考试平均最低的学生的姓名以及所选的课程名,select sname,cname from student s join sc on s.sno=sc.sno join course c on o=o where sdept=,计算机系,and sno=(select top 1 sno from sc order by ave(grade)asc),24,、查询,1-5,学期中选课人数最少的课程的课程名、开课学期和学分,SELECTCname,Semester,Credit,FROMCourseWHERE(CnoIN,(SELECTTOP1WITHtiescnoFROMsc,GROUPBYcno,ORDERBYCOUNT(*)ASC)AND(SemesterBETWEEN1AND5),25,、,create table test_t(,col1 int,col2 char(10)not null,col3 char(10),insert into test_t(col2)values(b1),insert into test_t(col1,col2,col3)values(1,b2,c2),insert into test_t(col1,col2)values(2,b3),26,、删除考试成绩低于,50,分的学生的该门课程的选课记录,delete from sc where grade60 and sdept=,计算机系,29,、删除,VB,考试成绩最低的学生的,VB,选课记录,delete from sc join student s on s.sno=sc.sno join course c on o=o where cname=vb and grade=(select min(grade)from sc join student s on sc.sno=s.sno where cname=vb),30,、将第,2,学期开设的所有课程的学分增加,2,分,update course set credit=credit+2,where semester=2,31,、将,VB,课程的学分改为,3,分,update course set credit=credit+2,where cname=vb,32,、将计算机系学生的年龄增加,1,岁,update student set sage=sage+1,where sdept=,计算机系,33,、将信息系学生的“计算机文化学”课程的考试成绩加,5,分,update sc set grade=grade+5 where cno in(select cno from course where cname=,计算机系,)and sno in(select sno from student where sdept=,信息系),34,、将选课人数最少的课程的学分降低,1,分,update course set credit=credit-1 where cno=(select top 1 cno from sc group by cno order by count(*)asc),第六章作业,9,、,1),在,student,表上为,sname,列建立一个聚集索引,索引名为,sldx,create clustered index sldx on student(sname),2),在,course,表上为,cname,列建立一个唯一的非聚集索引,索引名为,cnidx,create unique nonclustered index cnidx on course(cname),3),在,SC,表上为,SNO,和,CNO,建立一个组合的聚集索引,索引名为,snocnoidx,Create clustered index snocnoidx on sc(sno,cno),4),删除,SNAME,列上建立的,sldx,索引,Drop index sldx,12,、,1),查询学生的学号、姓名、所在系、课程名、课程号、课程学分,create view v1 as,select s.sno,sdept,cno,cname,credit from student s join sc on s.sno=sc.sno join course c on o=o,2),查询学生的学号、姓名、选修的课程名和考试成绩,create view v2 as,select s.sno,sname,cname,grade from student s join sc on s.sno=sc.sno join course c on o=o,3),统计每个学生的选课门数,要求列出学生学号和选课门数,create view v3 as select sno,count(*)as total from sc group by sno,4),统计每个学生的选课总学分,要求列出学生学号和总学分(说明:考试成绩大于等于,60,分才能获得此门课
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 管理文书 > 施工组织


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

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


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