资源描述:
《实验四 sql语言 select查询操作》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、实验四SQL语言习题一习题二USEDATABASEjxglUSEjxglCreateTableStudent(SnoCHAR(5)NOTNULLPRIMARYKEY(Sno),SnameVARCHAR(20),SageSMALLINTCHECK(Sage>=15ANDSage<=45),SsexCHAR(2)DEFAULT'男'CHECK(Ssex='男'ORSsex='女'),SdeptCHAR(2));CreateTableCourse(CnoCHAR(2)NOTNULLPRIMARYKEY(Cno),Cnam
2、eVARCHAR(20),CpnoCHAR(2),CcreditSMALLINT);CreateTableSC(SnoCHAR(5)NOTNULLCONSTRAINTS_FFOREIGNKEYREFERENCESStudent(Sno),CnoCHAR(2)NOTNULL,GradeSMALLINTCHECK((GradeISNULL)OR(GradeBETWEEN0AND100)),PRIMARYKEY(Sno,Cno),CONSTRAINTC_FFOREIGNKEY(Cno)REFERENCESCourse(C
3、no));INSERTINTOStudentVALUES('98001','钱横',18,'男','CS');INSERTINTOStudentVALUES('98002','王林',19,'女','CS');INSERTINTOStudentVALUES('98003','李民',20,'男','IS');INSERTINTOStudentVALUES('98004','赵三',16,'女','MA');INSERTINTOCourseVALUES('1','数据库系统','5',4);INSERTINTOCou
4、rseVALUES('2','数学分析',null,2);INSERTINTOCourseVALUES('3','信息系统导论','1',3);INSERTINTOCourseVALUES('4','操作系统原理','6',3);INSERTINTOCourseVALUES('5','数据结构','7',4);INSERTINTOCourseVALUES('6','数据处理基础',null,4);INSERTINTOCourseVALUES('7','C语言','6',3);INSERTINTOSCVALUES('
5、98001','1',87);INSERTINTOSCVALUES('98001','2',67);INSERTINTOSCVALUES('98001','3',90);INSERTINTOSCVALUES('98002','2',95);INSERTINTOSCVALUES('98002','3',88);9课程表Course(课程号Cno,课程名Cname,先修课号Cpno,学分Ccredit)学生表Student(学号Sno,姓名Sname,年龄Sage,性别Ssex,所在系Sdept)学生选课表SC(学号S
6、no,课程号Cno,成绩Grade)(1)基于“教学管理”数据库jxgl,使用SQL的查询语句表示下列查询:①检索年龄大于23岁的男学生的学号和姓名;selectSno,SnamefromStudentwhereSage>'23'ANDSsex='男';②检索至少选修一门课程的女学生的姓名;selectSnamefromStudent,SCwhereSsex='女'ANDStudent.Sno=SC.Sno9groupbyStudent.Snamehavingcount(*)>=1;或者SelectSnameFro
7、mStudentWhereSsex='女'ANDSnoin(selectsnofromSCgroupbysnohavingcount(*)>=1);③检索王同学不学的课程的课程号;selectCnofromCoursewhereCourse.Cnonotin(selectCnofromSC,StudentwhereSC.Sno=Student.SnoANDSnameLIKE'王%');④检索至少选修两门课程的学生学号;selectDISTINCTStudent.SnofromStudent,SCWHEREStude
8、nt.Sno=SC.SnoGROUPBYStudent.SnoHAVINGCOUNT(*)>=2;⑤检索全部学生都选修的课程的课程号与课程名;注参考课本p111例题46SELECTCno,CnamefromCoursewherenotexists(select*fromstudentwherenotexists9(select*fromSCwhereSC.s