资源描述:
《数据库实验四答案.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、数据库实验四答案--实验四----1.定义“IS”系学生基本情况视图V_IS并查询结果;createviewV_ISasselect*fromSwhereSdept='IS'withcheckoption;select*fromV_IS;--2.将S,C,SC表中学生的学号,姓名,课程号,课程名,成绩定义为视图V_S_C_G并查询结果;createviewV_S_C_GasselectS.Sno,Sname,C.Cno,CnamefromS,C,SCwhereS.Sno=SC.SnoandC.Cno=SC.Cno;select*fromV_S
2、_C_G;--3.将各系学生人数,平均年龄定义为视图V_NUM_AVG并查询结果;createviewV_NUM_AVGasselectcount(Sno)DeptNum,avg(Sage)DeptAvgAge,SdeptfromSgroupbySdept;select*fromV_NUM_AVG;--4.定义一个反映学生出生年份的视图V_YEAR并查询结果;createviewV_YEARasselectSno,2012-SagebirthdayfromS;select*fromV_YEAR;--5.将各位学生选修课程的门数及平均成绩定义为视图V_AVG_
3、S_G并查询结果;createviewV_AVG_S_GasselectSC.Sno,count(SC.Cno)CountCno,avg(Grade)AvgGradefromS,C,SCwhereS.Sno=SC.SnoandC.Cno=SC.CnogroupbySC.Sno;select*fromV_AVG_S_G;--6.将各门课程的选修人数及平均成绩定义为视图V_AVG_C_G并查询结果;createviewV_AVG_C_Gasselectcount(SC.Sno)Cnum,avg(Grade)AvgGradefromS,C,SCwhereS.Sno
4、=SC.SnoandC.Cno=SC.CnogroupbySC.Cno;select*fromV_AVG_C_G;--7.查询平均成绩为90分以上的学生学号、姓名和成绩;selectSC.Sno,Sname,avg(Grade)AvgGradefromS,SCwhereS.Sno=SC.SnogroupbySC.Sno,Snamehavingavg(Grade)>90;--8.查询各课成绩均大于平均成绩的学生学号、姓名、课程和成绩;createviewV_AVGasselectSC.Cno,avg(Grade)AvgGradefromC,SCwhere
5、C.Cno=SC.CnogroupbySC.Cno;selectdistinctS.Sno,Sname,C.Cno,GradefromS,SC,C,V_AVGwhereS.Sno=SC.SnoandC.Cno=V_AVG.CnoandGrade>V_AVG.AvgGrade;--9.按系统计各系平均成绩在80分以上的人数,结果按降序排列;selectSdept,count(AvgGrade)NumfromS,V_AVG_S_GwhereS.Sno=V_AVG_S_G.SnoandAvgGrade>80groupbySdeptorderbyNumd
6、esc;--10通过视图V_IS,分别将学号为“S1”和“S4”的学生姓名更改为“S1_MMM”,”S4_MMM”并查询结果;insertintoS(Sno,Sname,Ssex,Sage,Sdept)values('200215121','三毛','男',21,'IS');insertintoS(Sno,Sname,Ssex,Sage,Sdept)values('200215124','紫薇','女',19,'IS');updat
7、eV_ISsetSno='S1_MMM'whereSno='200215121';updateV_ISsetSno='S4_MMM'whereSno='200215124';select*fromV_IS;--11.通过视图V_IS,新增加一个学生记录('S12','YANXI',19,'IS'),并查询结果;insertintoV_IS(Sno,Sname,Sage,Sdept)values('S12','YANXI
8、9;,19,'IS');select