数据库实验四--SQL中 group by和 having子句的应用

题目

涉及的表格
1、student表
在这里插入图片描述
2、teacher表
在这里插入图片描述
3、course表
在这里插入图片描述
4、score表
在这里插入图片描述
1、查询每个学生的选课情况。显示(学号、课程号)

select sno as 学号,cno as 课程号
from score
group by sno,cno

2、统计助教的人数。

select count(prof) as 助教人数
from teacher
where prof = '助教'

3、查询每门课程的最高分。

select cno,max(grade) as 最高分
from score
group by cno

4、查询每个学生所选课程的最高分。(显示学号、最高分)

select sno as 学号,max(grade) as 最高分
from score

5、统计有多少门课程被选修。

select count(distinct cno) as 被选修课程数
from score

6、查询每门课程的平均成绩。(显示课程号、平均成绩)

select cno as 课程号,avg(grade) as 平均成绩
from score
group by cno

7、统计有超过4个学生选修的课程的课程号。

select cno
from score
group by cno
having count(cno) > 4

8、查询平均分超过80的课程的课程名。

select cno
from score
group by cno
having avg(grade) > 80

9、查询哪些班的人数超过3人。

select class
from student
group by class
having count(class) >= 3
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值