文档详情

复习SQL关键语句.ppt

发布:2017-12-14约3.67千字共12页下载文档
文本预览下载声明
数据查询 T1 、在数据库student_db的数据表st_info中查询20岁以上的学生的学号、姓名、年龄等信息,并按年龄排序。 T2、 对student_db数据库输出所有课程的补考成绩单,要求给出学生的学号、姓名、课程号和成绩。 T3、查询所有“必须”课程的课程号、课程名称、学分和选修学生的姓名和分数。 T4、查询所有学生的总成绩,要求列出学号、姓名、总成绩,没有选修课程的学生的总成绩为空显示。 T5、查询所有男同学的选课情况,要求列出学号、姓名、课程名称和分数。 T1:在数据库student_db的数据表st_info中查询20岁以上的学生的学号、姓名、年龄等信息,并按年龄排序。 SELECT st_id AS 学号, st_name AS 姓名, year(getdate())-year(born_date()) AS 年龄 FROM st_info WHERE year(getdate())-year(born_data())20 ORDER BY year(getdate())-year(born_data()) T2:旧版实验指导书P31 对student_db数据库输出所有课程的补考成绩单,要求给出学生的学号、姓名、课程号和成绩。 SELECT st_info. st_id, st_info. st_name, s_c_info .c_no, s_c_info .score FROM st_info JOIN s_c_info ON st_info. st_id =s_c_info. st_id WHERE score60 T3:查询所有“必修”课程的课程号、课程名称、学分和选修学生的姓名和分数。 T3_(1): SELECT st_name, score FROM st_info JOIN s_c_info ON st_info.st_id=s_c_info.st_id WHERE c_no in (SELECT c_no FROM c_info WHERE c_type=‘选修’ ) 或者 SELECT st_name, score FROM st_info JOIN s_c_info ON st_info.st_id=s_c_info.st_id JOIN c_info ON s_C_info.c_no=c_info.c_no WHERE c_type=选修 T4:查询所有学生的总成绩,要求列出学号、姓名、总成绩,没有选修课程的学生的总成绩为空显示。 SELECT st_info.st_id, st_name, SUM(score) FROM st_info LEFT OUTER JOIN s_c_info ON st_info.st_id=s_c_info.st_id GROUP BY st_info.st_id, st_name T5:查询所有男同学的选课情况,要求列出学号、姓名、课程名称和分数。 SELECT st_info.st_id, st_name, c_name,score FROM st_info INNER JOIN s_c_info ON st_info.st_id=s_c_info.st_id INNER JOIN c_info ON s_c_info.c_no=c_info.c_no WHERE st_sex=‘男’ 存储过程与触发器 旧版实验指导书P35(T4_1) CREATE PROC getpractise @Dname char(30) AS select st_info.st_id, st_name, c_info.c_no,c_name from c_info,st_info, s_C_info,d_info where c_info.c_no in (select c_no from c_info where c_type=实践 ) and st_info.st_id=s_c_info.st_id and c_info.c_no=s_c_info.c_no and d_info.d_id=left(st_info.st_id,2) and d_info.d_name=@Dname 旧版实验指导书P35 T5 Alter PROC getpctstu @Dname char(30), @name char(30) output AS if not exists(s
显示全部
相似文档