全表查询
语法:
Select * from 表名称;
描述:
查询指定表中的所有数据
案例:
![](https://img.haomeiwen.com/i13103779/4f1a3faffc07bb31.png)
单条件查询
语法:
select * from 表名称where 条件;
描述:
当进行全表数据查询时,测试指定的条件是否为True,将条件为True的所有数据进行查询展示,其他数据,不予展示。
案例:
![](https://img.haomeiwen.com/i13103779/42a541613fe4d792.png)
多条件查询:并且 | 或者
语法:
并且:与查询
select * from 表名称 where 条件1and条件2 and 条件n;
或者:或查询
select * from 表名称 where 条件1or条件2 or 条件n;
描述:
当进行全表查询时,可以根据多个条件共同查询
案例:
![](https://img.haomeiwen.com/i13103779/a312163b4f98250c.png)
![](https://img.haomeiwen.com/i13103779/6ce42b009327e42d.png)
模糊查询
语法:
select *
from 表名称where
name like (%/_)条件(%/_)
描述:
查询条件中的数据,只是查询数据的一部分~~通过一部分数据完成整体数据的匹配匹配过程,称为模糊匹配过程
案例:
![](https://img.haomeiwen.com/i13103779/665ff4df5ee80f52.png)
![](https://img.haomeiwen.com/i13103779/1f543fd50db484f2.png)
空值查询
语法:
select *
from 表名称 where 条件is null;
select *
from 表名称 where 条件is not null;
描述:
根据条件查询空与非空数据
案例:
![](https://img.haomeiwen.com/i13103779/45f6e794e7b3e46d.png)
范围查询
语法:
select * from 表名称 where 字段in (值1, 值2, 值3, … 值n);
描述:
可以手工指定多个数据,通过范围查询操作符号in,来指定条件取值范围,获取相关数据
案例:
![](https://img.haomeiwen.com/i13103779/3f1fa8e070c198d1.png)
范围查询:区间查询
语法:
select *
from 表名称where id between 1 and 10;
描述:
手工指定一个区间范围,包含起始数据和结束数据:between.. and ..
案例:
![](https://img.haomeiwen.com/i13103779/297597ab83185d90.png)
排序查询
语法:
select *
from 表名称 order by 列[asc|desc];
描述:
按照指定的列进行顺序或者降序的数据整理展示过程 asc 升序排列
desc 降序排列
案例:
![](https://img.haomeiwen.com/i13103779/61258bb1ea1ef3c4.png)
分页查询
语法:
select * from 表名称limit m, n;
描述:
查询一张表中的数据,起始id位m,查询n条
案例:
![](https://img.haomeiwen.com/i13103779/a102705c87f9a4d1.png)
聚合函数查询
语法:
select 函数from dept;
描述:
[if !supportLists]l [endif]avg() 求取指定列的平均值
[if !supportLists]l [endif]count() 求取指定列的数据总数量
[if !supportLists]l [endif]max()求取指定列中数据的最大值
[if !supportLists]l [endif]min()求取指定列中数据的最小值
[if !supportLists]l [endif]sum()求取指定列中数据的和
案例:
![](https://img.haomeiwen.com/i13103779/b3d8180f62b2053d.png)
指定列查询
语法:
select name, age form dept; 查询dept表中name和age两列
描述:
查询操作中,将数据表中的每一列数据全部展示
在查询过程中你,我们也可以通过列名称,指定查询的具体列
案例:
![](https://img.haomeiwen.com/i13103779/19ced065c9eade59.png)
查询数据剔重
语法:
select
distinct 列 from表名称;
描述:
查询数据表中指定列~所有不重复的数据,每个不重复的数据只会出现一次
案例:
![](https://img.haomeiwen.com/i13103779/e01db5c37d74cf1d.png)
分组查询
语法:
SELECT COUNT(1), darea FROM deptGROUP BYdarea;
SELECT COUNT(1), darea FROM deptGROUP BYdareahavingdarea is not null;
描述:
通过GROUP
BY 关键字,将数据表中,指定的列按照组的形式查询分别展示
案例:
![](https://img.haomeiwen.com/i13103779/605da569d56b6ac2.png)
网友评论