实验七数据查询
一实验目的1、掌握指定列或全部列查询2、掌握按条件查询3、掌握对查询结果的排序4、掌握使用聚集函数的查询5、掌握分组统计查询二实验内容
1、查询成绩在8090之间的记录代码:usejiaoxuedbgoselectfromStude
tSCwhereScorebetwee
80a
d90a
dSCS
oStude
tS
ogo结果:
2、查询至少有4个同学选修的课程名
代码:usejiaoxuedb
fgoselectC
amefromSCCoursewhereCourseC
oSCC
ogroupbyCourseC
amehavi
gCOUNTSCS
o4go结果:
3、查询其他系中比“信息系”所有学生年龄都大的学生名单及年龄,并按年龄降序输出。
代码:usejiaoxuedbgoselectS
ameAgefromStude
twhereAgeselectmaxAgefromStude
twhereDept信息a
dDept信息orderbyAgeDescgo结果:
f4、查询学生张建国同岁的所有学生的学号、姓名和系别。
代码:usejiaoxuedbgoselectS
oS
ameDeptfromStude
twhereAgeselectAgefromStude
twhereS
ame张建国a
dS
ame张建国go结果:
5、查询选修了两门以上课程的学生名单。
代码:usejiaoxuedb
fgoselectS
amefromStude
tSCwhereStude
tS
oSCS
ogroupbyStude
tS
amehavi
gCOUNT2go
6、查询至少有一门课程与“张建国”选课相同的学生的姓名、课程名和系别。
代码:usejiaoxuedbgoselectS
ameC
ameDeptfromStude
tSCCoursewhereStude
tS
oSCS
oa
dSCC
oCourseC
oa
dSCC
oi
selectC
ofromSCwhereS
oselectS
ofromStude
twhereS
ame张建国a
dS
ame张建国go结果:
7、查询成绩比该课程的平均成绩高的学生的成绩表。代码:
fusejiaoxuedbgoselectfromSCSC1whereScoreselectAVGScorefromSCSC2whereSC1C
oSC2C
ogo结果:
8、查询选修了课号为01001的课程且成绩高于课号为01002的课程的学生的姓名、两门课程的课程名和成绩。代码:
usejiaoxuedbgoselectS
ameC
ameScorefromStude
tSCCoursewhereStude
tS
oSCS
oa
dCourseC
oSCC
oa
dSCS
oi
selectSC1S
ofromSCSC1SCSC2whereSC1S
oSC2S
oa
dSC1C
o01001a
dSC2C
o01002a
dSC1ScoreSC2Scorego结果:
9、查询所有未选修01001号课程的学生名单。
f代码:UsejiaoxuedbGoSelectS
ameas姓名S
oas学号FromStude
tWhere
otexistsSelectfromSCWhereC
o’01001’a
dStude
tS
oSCS
oGo结果:
10、查询每个学生各门课程的平均成绩和最高成绩,按降序排列输出姓名、平均成绩和最高成绩。代码:
usejiaoxuedbgoselectS
ameas姓名avgScoreas平均成绩maxScoreas最高成绩fromStude
tSCwhereStude
tS
oSCS
ogroupbySCS
oS
ameorderbyS
amedescavgScoredescmaxScoreDescgo
结果:
f11、查询所有学生都选修了的课程的课程号和课程名。代码:
usejiaoxuedbgoselectC
oC
amefromCourser