MySQL查询练习(对上一条博客建的表)

查询练习

1.查询student表的所有记录。

select  * from student;

2.查询student表中的所有sname、ssex和class列。

select sname,ssex,class from student;

3.查询教师所有的单位即不重复的depart列。

select distinct depart from teacher;

distinct排重

4.查询score表中成绩在60~80的所有记录(区间查询)。

select * from score where degree between 60 and 80;

between…and…区间

或者

select * from score where degree > 60 and degree < 80;

5.查询score表中成绩为78、88、89的记录(或关系查询)。

select * from score where degree in (78,88,89); 

in在同一字段中的或查询

6.查询student表中“95001”班或女生的记录。

select * from student where class = '95001' or ssex = '女';

or不同字段的或查询

7.以class降序查询student表的所有记录。

​ 升序(默认):asc;

​ 降序:desc;

select * from student order by class desc;

8.以cno升序、degree降序查询score表的所有记录。

select * from score order by cno asc,degree desc;

先将cno升序排列,cno相同的以degree降序排列

9.查询“95002”班的学生人数。

select count(*) from student where class = "95002";

10.查询score表中的最高分的学生学号和课程号。(子查询或排序)

select sno,cno from score where degree = (select max(degree)from score); 

​ 实际步骤:

​ a.找到最高分select max(degree)from score;

​ b.找最高分的sno和cno。

11.查询每门课的平均成绩。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值