一在数据库school中建立student,sc,course表。学生表、课程表、选课表属于数据库School,其各自的数据结构如下:学生Student(Sno,Sname,Ssex,Sage,Sdept)序号列名含义数据类型长度1Sno学号字符型(char)62Sname姓名字符型(varchar)83Ssex性别字符型(char)24Sage年龄整数(smallint)5sdept系科字符型(varchar)15课程表course(Cno,Cname,Cpno,Ccredit)序号列名含义数据类型长度1Cno课程号字符型(char)42cname课程名字符型(varchar)203Cpno先修课字符型(char)44Ccredit学分短整数(tinyint)学生选课SC(Sno,Cno,Grade)序号列名含义数据类型长度1Sno学号字符型(char)62Cno课程号字符型(char)43Grade成绩小数(decimal)12,2二设定主码1Student表的主码:sno2Course表的主码:cno3Sc表的主码:sno,cno1写出使用CreateTable语句创建表student,sc,course的SQL语句createtablestudent(snochar(6),snamevarchar(8),ssexchar(2),sagesmallint,sdeptvarchar(15),primarykey(sno));Createtablecourse(Cnochar(4)primarykey,Cnamevarchar(20),Cpnochar(4),Ccredittinyint)createtablesc(snochar(6),cnochar(4),gradedecimal(12,2),primarykey(sno,cno));c2在student表中插入信息学号姓名性别年龄系科4001赵茵男20SX4002杨华女21JSJinsertintostudentvalues(’4001’,’赵茵’,’男’,20,’SX’)insertintostudentvalues(’4002’,’杨华’,’女’,21,’JXJ’)Delete1删除所有JSJ系的男生deletefromStudentwhereSdept=’JSJ’andSsex=’男’;2删除“数据库原理”的课的选课纪录deletefromSCwhereCnoin(selectCnofromCoursewhereCname=’数据库原理’);Update1修改0001学生的系科为:JSJUpdatestudentsetsdept=’JSJ’wheresno=’0001’2把陈小明的年龄加1岁,性别改为女。Updatestudentsetage=age+1,ssex=’女’wheresname=’陈小明’Select查询语句一单表1查询年龄在19至21岁之间的女生的学号,姓名,年龄,按年龄从大到小排列。selectsno,sname,sagefromstudentwheressex=’女’andsagebetween19and21orderbysagedesc;2查询姓名中第2个字为“明”字的学生学号、性别。selectsno,ssexfromstudentwheresnamelike’_明%’;3查询1001课程没有成绩的学生学号、课程号selectsno,cnofromscwheregradeisnullandcno=’1001’;4查询JSJ、SX、WL系的年龄大于25岁的学生学号,姓名,结果按系排列selectsno,snamefromstudentwheresdeptin(’JSJ’,’SX’,’WL’)andsage>25groupbysdept;5查询student表中的学生共分布在那几个系中。(distinct)selectdistinctsdeptfromstudent;6查询0001号学生1001,1002课程的成绩。selectgradefromscwheresno=’0001’and(cno=’1001’orcno=’1002’);二统计1查询姓名中有“明”字的学生人数。selectcount(*)fromstudentwheresnamelike’%明%’;2计算‘JSJ’系的平均年龄及最大年龄。selectavg(sage),max(sage)fromstudentwheresdept=’JSJ’;3计算每一门课的总分、平均分,最高分、最低分,按平均分由高到低排列selectcno,sum(grade),avg(grade),max(grade),min(grade)fromscgroupbycnoorderbyavg(grade)desc;4计算1001,1002课程的平均分。selectcno,avg(grade)fromscwherecnoin(‘1001’,’1002’)groupbycno;5查询平均分大于80分的学生学号及平均分select,avg(grade)fromscgroupbyhavingavg(grade)>80;6统计选修课程超过2门的学生学号selectsnofromscgroupbysnohavingcount(*)>2;7统计有10位成绩大于85分以上的课程号。selectcnofromscwheregrade>85groupbycnohavingcount(*)=10;8统计平均分不及格的学生学号selectsnofromscgroupbysnohavingavg(grade)<60;9统计有大于两门课不及格的学生学号selectsnofromscwheregrade<60groupbysnohavingcount(*)>2;三嵌套、相关及其他1查询平均分不及格的学生人数selectcount(*)fromstudentwheresnoin(selectsnofromscgroupbysnohavingavg(grade)<60)2查询没有选修1002课程的学生的学生姓名selectsnamefromstudentwheresnonotin(selectsnofromscwherecno=’1002’)3查询没有选修1001,1002课程的学生姓名。selectsnamefromstudentwheresnonotin(selectsnofromscwherecno=’1002’andcno=’1001’)