数据库期末复习资料(sql语句,触发器,存储过程).doc





《数据库期末复习资料(sql语句,触发器,存储过程).doc》由会员分享,可在线阅读,更多相关《数据库期末复习资料(sql语句,触发器,存储过程).doc(6页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Sql语言1、查询“00001”课程比“00002”课程成绩高的所有学生的学号select a.StuID as 学号from (select StuID,StuScores from Scores where CourseId=00001) a , (select StuID,StuScores from Scores where CourseId=00002) bwhere a.StuScoresb.StuScores and a.StuID=b.StuID select T1.StuID 学号 -使用自表连接from (select StuID,StuScores from Scores
2、 where CourseId = 00001) T1inner join (select StuID,StuScores from Scores where CourseId = 00002) T2on T1.StuID = T2.StuIDwhere T1.StuScoresT2.StuScores-2、查询平均成绩大于60分的学号和平均成绩select StuID as 学号,avg(StuScores) as 成绩from Scoresgroup by StuID having avg(StuScores)60 -3、查询所有同学的学号,姓名,选课数,总成绩select Student
3、s.StuID as 学号,Students.StuName as 姓名,count(Scores.CourseId) as 选课总数,sum(StuScores) as 总分from Students left join Scores on Students.StuID=Scores.StuIDgroup by Students.StuID,StuName -4、查询姓“易”的老师个数select COUNT(distinct(Teacher) as 个数from Coursewhere Teacher like 易%-5、查询没学过“易文龙”老师课的同学的学号,姓名select Stude
4、nts.StuID as 学号,Students.StuName as 姓名from Studentswhere StuID not in (select distinct(Scores.StuID) from Scores,Course where Scores.CourseId=Course.CourseId and Teacher=易文龙)-6、查询学过“00001”并且也学过编号“00002”课程的同学的学号,姓名select a.StuID as 学号,StuName as 姓名from Students a,Scores b,(select * from Scores where
5、courseId = 00001) cwhere b.CourseId=00002 and a.StuID = b.StuID and a.StuID = c.StuID-7、查询学过“易文龙”老师所教的所有课程同学的学号,姓名select StuID as 学号,StuName as 姓名 from Students awhere not Exists(select * from Course b where Teacher = 易文龙 and not Exists (select * from Scores c where c.StuID=a.StuID and c.CourseId=b.
6、CourseId)-8、查询课程编号“00002”的成绩比课程编号“00001”课程低的所有同学的学号,姓名select a.StuID as 学号,a.StuName as 姓名from (select Scores.StuID,StuScores,Students.StuName from Scores inner join Students on Scores.StuID = Students.StuID and CourseId=00001) a , (select StuID,StuScores from Scores where CourseId=00002) bwhere a.S
7、tuScoresb.StuScores and a.StuID=b.StuID -9、查询所有课程成绩小于60分的同学学号和姓名select StuID as 学号,avg(StuScores) as 平均分from Scoresgroup by StuID having avg(StuScores)60;select T1.StuID,StuNamefrom (select StuID from Scores group by StuID having MAX(StuScores)=60) T1inner join Students T2 on T1.StuID = T2.StuID -10
8、、查询没有学过所有课的同学的学号,姓名select Students.StuID as 学号,Students.StuName as 姓名from Students,Scoreswhere Students.StuID=Scores.StuIDgroup by Students.StuID,Students.StuName having count(CourseId)(select count(CourseId)from Course)-会漏掉未选修课的学生,应该使用以下方法select T2.*from(select StuID from Scores group by StuID havi
9、ng COUNT(*) = (select COUNT(*) from Course) T1right join Students T2 on T1.StuID=T2.StuIDwhere T1.StuID is null-11、查询至少学过“王丽秋”同学所学一门课的其他同学学号和姓名select Students.StuID as 学号,StuName as 姓名from Students,Scoreswhere Students.StuID=Scores.StuID and Students.StuName != 王丽秋 and CourseId in (select CourseId f
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据库 期末 复习资料 sql 语句 触发器 存储 过程

限制150内