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 字段名