数据查询语言DQL
1、单表查询
(1)全表查询:select * from 表名;
(2)查询指定列:select 字段1[,字段2,…] from 表名;
(3)查询不重复的数据:select distinct 字段名 from 表名;
(4)设置别名:select 字段名 as 列别名 from 原表名 [as ]表别名;
(5)条件查询:select 字段1[,字段2,…] from 表名 where 筛选条件;
(6)空值查询:select 字段1[,字段2,…] from 表名 where 空值字段 is[ not] null;
(7)模糊查询:select 字段1[,字段2,…] from 表名 where 字符串字段[ not] like 通配符;
(8)聚合运算:将多行数据进行聚集计算为一行,聚合函数会对null以外的数据进行聚合运算
(9)分组查询:select 字段1[,字段2,…] from 表名[ where 查询条件] group by 分组字段1[,分组字段2,…];
(10)分组后筛选:select 字段1[,字段2,…] from 表名[ where 查询条件][ group by 分组字段1[,分组字段2,…]] having 筛选条件;
(11)查询结果排序:select 字段1[,字段2,…] from 表名 order by 字段1[ 排序方向,字段2 排序方向,…];
(12)限制查询结果数量:select 字段1[,字段2,…] from 表名 limit [偏移量,] 行数;
2、多表查询
(1)连接查询
(2)内连接
(3)左连接
(4)右连接
(5)笛卡尔积
(6)自连接
3、合并查询
(1)union去重:select 字段1[,字段2,…] from 表名 union select 字段1[,字段2,…] from 表名;
(2)union all不去重: select 字段1[,字段2,…] from 表名 union all select 字段1[,字段2,…] from 表名;
4、子查询
一个select语句中包含另一个或多个完整的select语句
5、常用函数
(1)字符串函数
(2)数学函数
(3)日期时间函数
(6)开窗函数
(7)序号函数








暂无数据