交互式SQL-子查询和数据操纵命令zwf(2)

2018-12-06 19:16

','计算机文化基础',3,1);

InsertintoCourse(Cno,Cname,Ccredit,Semster)Values('C02','VB',2,3);

InsertintoCourse(Cno,Cname,Ccredit,Semster)Values('C03','计算机网络',4,7);

InsertintoCourse(Cno,Cname,Ccredit,Semster)Values('C04','数据库基础',6,6);

InsertintoCourse(Cno,Cname,Ccredit,Semster)Values('C05','高等数学',8,2);

InsertintoCourse(Cno,Cname,Ccredit,Semster)Values('C06','数据结构',5,4); --SC数据

InsertintoSC(Sno,Cno,Grade,XKLB)values('9512101','C01',90,'必修');

InsertintoSC(Sno,Cno,Grade,XKLB)values('9512101','C02',86,'选修');

InsertintoSC(Sno,Cno,Grade,XKLB)values('9512101','C06',62,'必修');

InsertintoSC(Sno,Cno,Grade,XKLB)values('9512102','C02',78,'选修');

InsertintoSC(Sno,Cno,Grade,XKLB)values('9512102','C04',66,'必修');

InsertintoSC(Sno,Cno,Grade,XKLB)values('9512102','C01',82,'选修');

InsertintoSC(Sno,Cno,Grade,XKLB)values('9512102','C05',92,'必修');

InsertintoSC(Sno,Cno,Grade,XKLB)values('9512102','C06',50,'必修');

InsertintoSC(Sno,Cno,Grade,XKLB)values('9512103','C02',68,'选修');

InsertintoSC(Sno,Cno,Grade,XKLB)values('9531103','C06'

6

,62,'必修');

InsertintoSC(Sno,Cno,Grade,XKLB)values('9531101','C01',80,'选修');

InsertintoSC(Sno,Cno,Grade,XKLB)values('9531101','C05',95,'必修');

InsertintoSC(Sno,Cno,Grade,XKLB)values('9531102','C05',85,'必修');

--(2)把王敏同学的所在系改为信息系; updateStudent setSdept='信息系' whereSname='王敏';

--(3)把数据库基础改名为数据库原理与应用; updateCourse

setCname='数据库原理与应用' whereCname='数据库基础';

--(4)删除成绩小于分的选课信息;************ delete fromSC

whereGrade<40;

--4、使用嵌套查询,(1)查询课程成绩大于分的学生的姓名、性别和所在系;

selectSname,Ssex,Sdept fromStudent whereSnoin( selectSno fromSC

whereGrade>90 );

--(2)查询计算机系所有学生的C02号课程的成绩,列出学号和成绩,并按成绩由高到低排序;

7

selectSno,Grade fromSC

whereCno='C02'andSnoin( selectSno fromStudent

whereSdept='计算机系' )

ORDERbyGradeDESC;

--(3)查询出成绩大于该课程平均分的学生的学号、课程号和成绩;p/107 selectSno,Cno,Grade fromSCx

whereGrade>(

selectAVG(Grade) fromSCy

wherey.Sno=x.Sno);

--(4)查询哪些学生没有选课,要求列出学号、姓名、性别和所在系;p/111 selectSno,Sname,Ssex,Sdept fromStudent

wherenotEXISTS( select* fromSC

whereSno=Student.Sno );

--(5)查询既选修了C03号又选修了C05号课程的学生的姓名、性别和所在系;p/113

selectSname,Ssex,Sdept fromStudent whereSnoin( selectSno fromSC

whereCno='C03'andSnoin( selectSno fromSC

whereCno='C05' ));

--(6)查询信息系成绩在分以上的学生的学号、姓名; selectSno,Sname fromStudent

whereSdept='信息系'andSnoin(

8

selectSno fromSC

whereGrade>80 );

--(7)查询数学系考试成绩最高的学生的姓名; selectSname fromStudent whereSnoin( selectSno fromSC

whereGradein( selectMAX(Grade) fromSC

whereSdept='数学系' ));

--(8)查询选修了所有课程的学生的学号、姓名、性别和所在系;p/111 selectSno,Sname,Ssex,Sdept fromStudent

wherenotexists( select* fromCourse

wherenotexists( select* fromSC

whereSno=Student.SnoandCno=Course.Cno ));

--5、使用集合查询(1)查询是数学系或者是信息系学生的姓名、性别、年龄和所在系;

selectSname,Ssex,Sage,Sdept fromStudent

whereSdept='数学系'

union

selectSname,Ssex,Sage,Sdept fromStudent

whereSdept='信息系';

--(2)查询信息系年龄大于岁的学生的学号、姓名、性别;注意参数 selectSno,Sname,Ssex fromStudent

9

whereSdept='信息系' intersect

selectSno,Sname,Ssex fromStudent whereSage>18;

--(3)查询既选了C01号课程又选了C04号课程的学生的学号; selectSno fromSC

whereCno='C01' intersect selectSno fromSC

whereCno='C04';

--(4)查询既不姓张也不姓王的学生的学号、姓名和所在系; selectSno,Sname,Sdept fromStudent

whereSnamenotlike'张%' intersect

selectSno,Sname,Sdept fromStudent

whereSnamenotlike'王%';

4.3出现的问题:

答:第5题(2)中应注意注意上下参数要一致。

4.4 解决方案(列出遇到的问题和解决办法,列出没有解决的问题

10


交互式SQL-子查询和数据操纵命令zwf(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:嘉禾县山潭村革命烈士名熙公简传

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: