1>按一定条件查询某字段的数据 (where)
select * from students1 where id>3; ( 查询 id > 3 的数据)
#补充:
select * from students1 where id<3;
注意“ select * from students1; (此命令需谨慎使用, 数据量大可能导致爆内存)
2>给字段取别面并查询 ( 只是便于查询,没有做修改)
select name as '姓名' ,age as '年龄' from students1;
3> 给表取别名并查询
select lichao.name lichao.age from students1 as lichao;
4>查看某字段里的数据并消除重复的行 ( 重复的行不显示)
select distinct age from students1;
5>查询id字段里 id大于4 而小于7的数据 (条件查询) ( 满足 两个条件)
select * from students where id>4 and id<7;
#补充
select * from students1 where age>30 and age<60;
#补充2
select * from students1 where age>40 && age<60;
6>条件查询(满足其中一个条件即可)( or)
select * from students1 where id>5 or age<33;
#补充
select * from students1 where id>3 || age<33;
7>模糊查询
select * from studens1 where name like ’%杰%'; (查找name 类似于 杰的 杰前面和后面可以有任意字符)
#补充
select * from students1 where name like ‘杰%';
#补充2
select * from students1 where name like '___'; ( 查找名字为三个字符的人名) ( 一个下斜杠代表一个字符)
#补充3
select * from students1 where name like ’___%'; ( 至少三个字符)
8> 范围查询 ( 非连续型范围内)
select * from students1 where age in(22,19,44,45);
9>查询 age 在22与34 之间的人数
select * from students1 where age betewn 22 and 34;
#也可以这样写
select * from students1 where ( age between 22 and 34);
#补充 ( 取反)
select * from students1 where age not between 22 and 34;
10>为空判断 、
select * from students1 where high is null; ( 查询 high字段 为空的 某条(些)数据)
11>非空判断
select * from students1 where high is not null;
12>排序
#1从小到大
select * from students1 oder by age asc; ( 按 age 的 从小 到大进行排序)
#2 从大到小
select * from students1 order by age desc; ( 按 age 的 从大到小进行排序)
&补充
select * from students1 where ( age between 22 and 46 ) order by age asc; ( 把 年龄在 22 到 46 岁之间的人 按年龄从小到大进行排序)
&补充2
select * from students1 where ( age between 22 and 34 ) and gander=1 order by high asc; ( 把 年龄在22 和 34 之间的男性 按 身高 从矮到高进行排列 ) ( 包括 22 和 34 )