1>按一定条件查询某字段的数据 (where)

select  *  from students1 where  id>3; (  查询 id > 3 的数据)

MariaDB  ----单表查询

#补充:

select * from students1  where id<3;

MariaDB  ----单表查询

注意“ select * from  students1;  (此命令需谨慎使用, 数据量大可能导致爆内存)

2>给字段取别面并查询  ( 只是便于查询,没有做修改)

select   name  as  '姓名' ,age  as '年龄'  from  students1;

MariaDB  ----单表查询

3> 给表取别名并查询

select   lichao.name   lichao.age  from  students1 as lichao;

MariaDB  ----单表查询

4>查看某字段里的数据并消除重复的行 ( 重复的行不显示)

select   distinct  age  from students1;

MariaDB  ----单表查询

5>查询id字段里  id大于4 而小于7的数据  (条件查询)  ( 满足 两个条件)

select  * from students  where  id>4 and id<7;

MariaDB  ----单表查询

#补充

select * from  students1  where  age>30 and age<60;

MariaDB  ----单表查询

#补充2

select  * from students1 where  age>40 && age<60;

MariaDB  ----单表查询

6>条件查询(满足其中一个条件即可)( or)

select * from students1 where  id>5 or age<33;

MariaDB  ----单表查询

#补充

select * from students1 where id>3 || age<33;

MariaDB  ----单表查询

7>模糊查询

select * from studens1   where name like ’%杰%'; (查找name 类似于 杰的       杰前面和后面可以有任意字符)

MariaDB  ----单表查询

#补充

select  * from  students1  where name like  ‘杰%';

MariaDB  ----单表查询

#补充2

select * from students1 where name like '___'; ( 查找名字为三个字符的人名)  ( 一个下斜杠代表一个字符)

MariaDB  ----单表查询

#补充3

select * from students1  where name like ’___%';  ( 至少三个字符)

MariaDB  ----单表查询

8> 范围查询  ( 非连续型范围内)

select  * from students1 where  age in(22,19,44,45);

MariaDB  ----单表查询

9>查询 age 在22与34 之间的人数

select   * from  students1 where  age betewn 22 and 34;

MariaDB  ----单表查询

#也可以这样写

select  * from students1 where ( age between  22 and 34);

MariaDB  ----单表查询

 #补充 ( 取反)

select * from students1  where age not between  22 and 34;

MariaDB  ----单表查询

10>为空判断 、

select  * from  students1  where  high is null; ( 查询  high字段 为空的 某条(些)数据)

MariaDB  ----单表查询

11>非空判断

select * from students1  where  high is not null;

MariaDB  ----单表查询

12>排序

#1从小到大

select  * from students1  oder by age asc;  ( 按 age 的 从小 到大进行排序)

MariaDB  ----单表查询

#2 从大到小

select * from students1 order by age desc; ( 按 age 的 从大到小进行排序)

MariaDB  ----单表查询

&补充

select * from students1 where ( age between  22 and 46 )   order by age asc; (   把  年龄在 2246 岁之间的人 按年龄从小到大进行排序)

MariaDB  ----单表查询

&补充2

select * from students1 where ( age  between 22 and 34 )  and  gander=1 order  by high  asc;

(  把  年龄在22 和 34 之间的男性 按 身高 从矮到高进行排列  )     (  包括 2234
View Code

相关文章:

  • 2022-12-23
  • 2021-09-11
  • 2022-12-23
  • 2021-12-09
猜你喜欢
  • 2022-02-26
  • 2021-04-07
  • 2022-12-23
  • 2022-12-23
  • 2021-10-10
  • 2021-10-26
  • 2021-09-17
相关资源
相似解决方案