实验报告(四)
1、实验目的
(1) 掌握表连接的外连接用法和应用场合
(2) 掌握对聚集函数的使用
(3) 掌握对分组的使用
(4) 掌握行数限制的方法
2、实验预习与准备
(1) 了解外连接中左连接、右连接和全连接的作用
(2) 了解内外连接的区别
(3) 了解Max,Min,Avg,Sum,Count的语法格式
(4) 了解Group by子句的作用
(5) 了解Having子句与Where子句的区别
3、实验内容及步骤
(1) 查询没有任何学生选学的课程编号和课程名称及学分
mysql> select course.cno, course.cname, course.credit
-> from course
-> where course.cno not in
-> (select cno from score);
(2) 查询每个班学生入学成绩最高分和最低分的差距,列名为“最大分差”
mysql> select student.clno, MAX(point)-MIN(point) as 最大分差
-> from student
-> group by clno;
(3) 查询至少选修了三门课程的学生编号
mysql> select sno
-> from score
-> group by sno having count()>2;
(4) 统计各个班级男生和女生的平均年龄及人数。
mysql> select clno,sex, AVG(YEAR(now())-YEAR(birth)) as 平均年龄,
-> count() as 人数
-> from student
-> group by clno, sex;
(5) 查询至少被两名学生选修的课程名称
mysql> select course.cname
-> from course
-> where course.cno not in (select score.cno from score group by sno having count(*)<2);
(6) 查询计算机学院至少有两门课的成绩在80以上的女学生学号、姓名和出生日期及其期末成绩的最高分
mysql> select student.sno, student.sname, student.birth, MAX(score.score)
-> from student, score, course, class
-> where class.department=‘计算机学院’ and class.clno=student.clno
-> and student.sex=‘女’ and student.sno=score.sno
-> group by score.sno
-> having count(score>=80)>2;
(7) 查询所选课程期末成绩平均分在85分以上的“女”学生学号、姓名、期末成绩平均分
mysql> select student.sno, student.sname, avg(score.score) as 期末成绩平均分
-> from student, score
-> where student.sex=‘女’ and student.sno=score.sno
-> group by score.sno
-> having avg(score.score)>=85;
(8) 查询“马克思主义基本原理”期末成绩排在6-10名的学生学号、姓名和期末成绩
mysql> select student.sno, student.sname, score.score
-> from student, score, course
-> where student.sno=score.sno and course.cname=‘马克思主义基本原理’
-> order by score.score desc
-> limit 5,5;
4、实验中的问题及解决方法:
(1) 问题一描述……
解决方法
(2) 问题二描述
解决方法
5、 实验感想与总结
MySQL实验报告(四)
最新推荐文章于 2023-06-17 11:15:32 发布