实验目的:
- 掌握使用集函数的单表查询。
-
实验内容:
对JXGL数据库进行查询。
查询学生总人数。
select count(*) as '总人数' from student
查询选修了课程的学生人数。
select count(distinct sno) as '人数' from sc
计算1号课程的学生平均成绩。
select avg(grade) as '平均分' from sc where cno='1'
查询选修1号课程的学生最高分数。
select max(grade) as '最高分' from sc where cno='1'
计算选修1号课程的学生人数、最高成绩、最低成绩及平均成绩。
select count(*) as '人数',max(grade) as '最高分',min(grade) as '最低分',avg(grade) as '平均分' from sc where cno='1'
求各个课程号及相应的选课人数。
select cno,count(*) as '选课人数' from sc group by cno
查询选修了3门以上课程的学生学号。
select sno from sc group by sno having count(*)>=3
查询有3门以上课程是90分以上的学生的学号。
select sno from sc where grade>90 group by sno having count(*)>=3
查询各专业的专业名及学生人数。
select sdept,COUNT(*) as '学生人数' from student group by sdept
查询平均成绩在80分以上的学生的学号及平均成绩
select sno,AVG(grade) as '平均成绩' from sc group by sno having AVG(grade)>80
查询至少有2个人选修的课程的课程号,选课人数。
select cno,COUNT(*) as '选课人数' from sc group by cno having COUNT(*)>=2
查询选修了3号课程的学生的学号及其成绩,查询结果按分数降序排列。
select sno,grade from sc where cno='3' order by grade desc
查询全体学生情况,查询结果按所在系的系号升序排列,同一系中的学生按年龄降序排列。
select * from student order by sdept asc,sage desc