数据库作业
- 格式:docx
- 大小:13.41 KB
- 文档页数:1
设有3个表,其中:学生表student,内有学号、姓名、性别、出生年月、专业、入学成绩等字段;成绩表score1内有学号、课程号和成绩字段课程表course内有课程号、课程名、主讲教师、学分等字段按照要求写命令:
1)输出学生表中入学成绩高于400分的男生和计算机专业的学生
select * from student where 入学成绩>400 and 性别='男'and 专业='计算机'
2)要求查找学生的姓名,所学的课程名,成绩和学分
select a.姓名,c.课程名,b.成绩,c.学分from student a, score1 b, course c where a.学号=b.学号and b.课程号=c.课程号
3)要求查找选修了《计算机应用基础》其成绩大于80分学生姓名,成绩。
select a.姓名,b.成绩from student a, score1 b, course c where a.学号=b.学号and b.课程号=c.课程号and c.课程名='计算机应用基础' and b.成绩>80
4)要求查找姓李的学生的姓名,所学的课程名,成绩和学分,并按成绩降序排列
select a.姓名,c.课程名,b.成绩,c.学分from student a, score1 b, course c where a.学号=b.学号and b.课程号=c.课程号and a.姓名like '李%' order by b.成绩desc
5)查询选修了至少3门课的学号姓名和班级。
select a.学号,a.姓名,a.班级from student a, score1 b, course c where a.学号=b.学号group by a.学号having count(b.课程号)>=3
6) 要求查找1990年出生的女生姓名。
select 姓名from student where 性别='女' and year('出生年月')='1990'
7)查找学生表包含“红”字和姓李的学生学号、姓名、性别和入学成绩
select 学号,姓名,性别,入学成绩from student a, score1 b where a.学号=b.学号and 姓名like '%红%' and 姓名like '李%'
8)按选修了某一门课程的男生生成一个表(按成绩降序)
select a.* into new_student from student a, score1 b,course c where a.学号=b.学号and b.课程号=c.课程号and c.课程名='数据库' order by b.成绩desc
9)查询和“进步”同学入学成绩相同的同学信息
select * from student where 入学成绩=(select 入学成绩from student where 姓名='进步')
10)查询选修了数据库课的学生学号,姓名和成绩并按成绩降序排列。
select a.学号,a.姓名,b.成绩from student a, score1 b,course c where a.学号=b.学号and b.课程号=c.课程号and c.课程名='数据库' order by b.成绩desc。