【分组查询和统计计算】

#【例6.10】查询student表中姓董的学生情况。
select * from student where sname like '董%';
#【例6.11】查询含有“系统”或“数字”的所有课程名称。
select * from course where cname regexp '系统|数字';
#【例6.12】求学生的总人数。
select count(*) AS 总人数 from student;
#【例6.13】查询通信专业学生的总人数。
select count(*) as 总人数 from student where speciality='通信';
#【例6.14】查询1201课程总分。
select sum(grade) as 课程1201总分 from score where cno='1201';
#【例6.15】查询8001课程的最高分、最低分、平均成绩。
select max(grade) as 课程8001最高分,min(grade) as 课程8001最低分,avg(grade) as 课程8001平均成绩
    from score where cno='8001';
#【例6.16】查询各门课程的最高分、最低分、平均成绩。
select cno as 课程号,max(grade) as 最高分,min(grade) as 最低分,avg(grade) as 平均成绩
from score where not grade is null group by cno;
#【例6.17】查询平均成绩在90分以上的学生的学号和平均成绩。
select sno as 学号,avg(grade) as 平均成绩 from score group by sno having avg(grade)>90;
#【例6.18】查询至少有5名学生选修且以8开头的课程号和平均分数。
select cno as 课程号,avg(grade) as 平均分数 from score 
    where cno like'8%' group by cno having count(*)>5;
#【例6.19】将计算机专业的学生按出生时间降序排序。
select * from student where speciality='计算机' order by sbirthday desc;
#【例6.20】查询成绩表中成绩前3位学生的学号、课程号和成绩。
select sno,cno,grade from score order by grade desc limit 3 offset 0;

#【例6.21】采用交叉连接查询教师和和讲课地点所有可能组合。
select tname,location from teacher,lecture;
#【例6.22】查询每个学生选修课程的情况。
select student.*,score.* from student,score where student.sno=score.sno;
 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冯阳xx

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值