当前位置:首页 > 10.21《数据库系统概论》实验报告五
题目:实验五 数据库的分组查询和统计查询 班级 2012计算机 学号 201251401137 姓名 曹彦春 日期 2013-10-21 实验内容与完成情况(比如 写出每一种SQL语句的用例,截图其结果 使用聚集函数 1. 查询学生总人数:Select Count(*) as 学生总数 from student;、 2. 查询选修了课程的学生总数:select count(distinct sno) as 选课学生总数 from sc; 3. 查询所有课程的总学分数和平均学分数,以及最高学分和最低学分: select sum(credit) as 总credit, avg(credit) as 课程平均学分,max(credit) as 最高学分, min(credit) as 最低学分 from course;
4. 计算1号课程的学生的平均成绩, 最高分和最低分: select avg(grade) as 平均成绩, max(grade) as 最高分, min(grade) as 最低分from sc where cno='1'; 5. 查询’信息系’(IS)学生”数据结构”课程的平均成绩: select avg(grade) from student, course, sc where student.sno=sc.sno and course.cno=sc.cno and sdept='IS' and cname='数据结构'; 分组查询 6. 查询各系的学生的人数并按人数从多到少排序 : Select sdept, Count(*) as 人数 from student group by sdept order by 人数 desc; 7. 查询各系的男女生学生总数, 并按系别,升序排列, 女生排在前: select sdept,ssex,Count(*) as 人数 from student group by sdept, ssex order by sdept,ssex desc; 8. 查询选修了3门课程已上的学生的学号和姓名: select sno, sname from student where sno in (select sno from sc group by (sno) having count(*)>3); 9. 查询每个学生所选课程的平均成绩, 最高分, 最低分,和选课门数: select sno, avg(grade) as 平均成绩,max(grade) as 最高分, min(grade) as 最低分, count(*) as 选课门数 from sc group by sno; 10. 查询至少选修了2门课程的学生的平均成绩: select sno, avg(grade) as 平均成绩, from sc group by sno having count(*)>=2; 11. 查询平均分超过80分的学生的学号和平均分: Select sno, avg(grade) as 平均成绩from sc group by sno having avg(*)>=80; 比较: 求各学生的60分以上课程的平均分: select sno, avg(grade) as 平均成绩 from sc where grade>=60 group by sno; 12. 查询”信息系”(IS)中选修了5门课程以上的学生的学号: select sno from sc where sno in (select sno from student where sdept='IS') group by sno having count(*)>=2; 集合查询 13. 查询数学系和信息系的学生的信息; select * from student where sdept=’MA’union select * from student where sdept='IS'; 14. 查询选修了1号课程或2号课程的学生的学号: select sno from sc where cno='1' union select sno from sc where cno='2'; 比较实验四之3。 出现的问题与解决方案(列出遇到的问题和解决办法,列出未解决的问题): 无。
共分享92篇相关文档