本篇博客基于mysql的基本操作命令下的条件命令:
select * from table_name;
#显示table_name这张表中的所有信息
select name from students;
#查找students表中都有哪些学生(名字)
select name,age from students;
#查找students表中的有哪些学生,并且各自多大了
select * from students where sex='男';
#查找students表中性别是‘男’ 的学生信息
select * from students where name like '强';
#查找students表中name中带有‘强’的学生信息
select * from students order by age asc;
#将students按照age的大小进行升序排列
select * from students order by age desc;
#将students按照age的大小进行降序排列
select * from students where sex=boy and age>=10;
#查找students表中满足:性别是boy和年龄大于等于10的学生信息
select * from students where sex=boy or age>=10;
select * from students where degree between 60 and 80;
#查找students表中学生成绩在60~80之间的学生信息
select * from students where dagree in(85,75,90);
#students表中学生成绩为85,75,90的学生信息
select * from students where sex='男' order by age asc;
#查找students表中sex为‘男’,并且按照age的大小进行升序排列
select count(*) from students;
#查看students表中有多少行学生信息
select count(*) from students order by age desc;
#查看students表中有多少行学生信息,并且按照age的大小进行降序
select count(*) from students group by sex;
#g根据sex来查看students中‘男’、‘女’各有多少人
select sum(score) from students;
#查看students中学生成绩的总和
select avg(score) from students;
#查看students中学生成绩的平均值
select max(score),min(score) from students;
#查看students中学生成绩最大值和最小值
select max(score),min(age) from students;
#查看students中学生成绩的最大值和年龄的最小值
select sum(score) from students where sex='男' group by age>=15;
#先根据age>=15分组,再分别查找出sex=‘男’的score之和
select name,sex,age from students where job='打游戏' group by sex having name like '%强%';
#先查找出job=‘打游戏’,再根据sex分组,再次筛选出name中带有‘强’的人的name、sex、age
select * from students limit 10;
#查询10条记录
select * from students limit 2,8;
#从第三条开始查询,查询八条记录就可以了~~删除线格式~~
select class,sum(age)as s from School where age>7 group by class having s>=50;
#查询某学校各班大于7岁学生的年龄之和,并且只显示年龄之和大于等于50的班级
#注意:as是可以省略的
select * from students limit 2,-1;
#查询第三条到最后一条之间的记录
书写顺序:select ------>from ---------> where--------->group by -------->having --------->order by ------->linit
执行顺序:from--------> where---------> group by --------->having ----------> select ---------> order by --------> limit
书写顺序:select ------>from ---------> where--------->group by -------->having --------->order by ------->linit
执行顺序:from--------> where---------> group by --------->having ----------> select ---------> order by --------> limit
看完记得点个赞