MySQL常用查询操作

MySQL常用查询操作

1、查询表中所有的记录
select * from 表名;
‘*’ 代表所有字段

2、查询表中所有记录的一部分列
select 字段1,字段2,…,字段n from 表名;

3、查询表中某一列不重复的记录
select distinct 字段名 from 表名;
distinct 排除重复

4、查询处于区间中的记录
select * from 表名 where 字段名 between …… and ……;
查询成绩在60到80之间的记录
select * from score where degree between 60 and 80;
直接使用运算符比较
select * from score where degree>60 and degree<80;

5、查询score表中成绩为85,86或88的记录
select * from score where degree in(85,86,88);

6、查询student表中班级为“95031”或性别为“女”的记录
select * from student where class=‘95031’ or sex=‘女’;
or 表示或者

7、以class降序排列student表的所有记录
select * from student order by class desc;
降序 desc
升序 asc
默认升序

8、以no升序、degree降序查询score表的所有记录
select * from score order by cno asc,degree desc;

9、查询“95031”班的学生人数
统计 count
select count(*) from student where class =‘95031’;

10、查询score表中的最高分的学生的学号和课程号(子查询)
select sno, cno from score where degree=(select max(degree) from score);
查询某列的最大值
select max(degree) from score;
查询某列的最小值
select min(degree) from score;

11、分组计算平均值
select no,avg(degree) from score group by no;
分组 :group by 字段名

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值