数据库实验二Word格式文档下载.docx
《数据库实验二Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《数据库实验二Word格式文档下载.docx(14页珍藏版)》请在冰豆网上搜索。
4.在SQL
Server查询分析器中使用IN、比较符、ANY或ALL和EXISTS操作符进行嵌套查询操作。
二、实验内容
(1)查询数学系学生的学号和姓名。
(2)求选修了课程的学生学号。
(3)查询选修001号课程的学生学号和成绩,并要求对查询结果按成绩降序排列,如果成绩相同则按学号升序排列。
(4)求选修课程001且成绩在80—90分之间的学生学号和成绩,并将成绩乘以系数0.8输出。
(5)求数学系或计算机系姓张的学生的信息。
(6)查看选修了课程、但没有成绩学生的学号、姓名、课程号和所在系部。
(7)查询学生的学号、姓名、课程名和成绩。
(8)分别实现学生和系的交叉连接、内连接、外连接。
(9)求选修了高等数学的学生学号和姓名。
(10)求001课程的成绩高于张力的学生学号和成绩。
(11)求其他系中年龄小于计算机系年龄最大者的学生。
(12)求其他系中比计算机系学生年龄都小的学生。
(13)求选修了001课程的学生姓名。
(14)求没有选修001课程的学生姓名。
(15)查询选修了全部课程的学生的姓名。
(16)求选修了学号为“200210102”的学生所选修的全部课程的学生学号和姓名。
selectstudent.sname,student.sno
fromstudent,depart
wherestudent.sdept=depart.sdepanddepart.dname='
数学系'
selectdistinct(student.sno)
fromstudent,sc
wherestudent.sno=sc.sno
selectstudent.sno,student.sname,sc.grade
wherestudent.sno=sc.snoandcno='
1'
orderbysc.gradedesc,student.snoasc
selectstudent.sno,(sc.grade)*0.8
wherestudent.sno=sc.snoando='
andsc.grade>
=80andsc.grade<
=90
select*
wherestudent.sdept=depart.sdep
anddepart.dnamein('
'
计算机系'
)
andstudent.snamelike'
张%'
wherestudent.sno=sc.snoandsc.gradeisnull
selectstudent.sno,student.sname,o,sc.grade
fromstudent,sc,course
wherestudent.sno=sc.snoando=o
右外连接
selectstudent.sno,student.sname,student.sdept
fromstudentleftjoindeparton(student.sdept=depart.sdep)
交叉连接
select*fromstudentcrossjoindepart
内连接
9)求选修了高等数学的学生学号和姓名。
selectstudent.sno,student.sname
wherestudent.sno=sc.snoando=oandame='
数学'
andsc.grade>
(selectsc.grade
wherestudent.sno=sc.snoando=oandstudent.sname='
张立'
andame='
selectstudent.sname
wherestudent.sage<
(selectmax(student.sage)
anddepart.dname<
>
'
andstudent.sdept=depart.sdep
all(selectstudent.sage
fromstudent
wherenotexists(
fromsc
wherenotexists(select*
fromcourse
wherestudent.sno=sc.snoando=o));
(16)求选修了学号为“95005”的学生所选修的全部课程的学生学号和姓名。
selectdistinctsno
fromscscx
select*
fromscscy
wherescy.sno='
95021'
andnotexists(select*
fromscscz
wherescz.sno=scx.snoando=o))