查询语句
1 select * from 表名;*(代表表中的所有字段)
2 select distinct 字段名 from 表名 ; distinct 去掉重复字段
3 select * from 表名 where 条件 ;where 添加查询的限制条件
比较运算符 >、<、>=、<=、!=、<>
逻辑运算符 and or not
模糊查询 like %代表多个 _代表一个 例: %like% 、_like%
4 查询结果排序
5 单字段排序: order by asc 升序 order by desc 降序 例:order by 字段 asc;
多字段 例如:order by 字段名 asc,字段名;
6 限制查询数量 limit
使用 select * from 表名 limit 0,3;从第一条开始 找三条数据
7 聚合函数
sum 函数 select sum(字段名) from 表名; 求某个字段的和
avg 函数 select avg(字段名) from 表名; 求某个字段的平均值
max 函数 select max(字段名) from 表名; 求某个字段的最大值
min 函数 select min(字段名) from 表名; 求某个字段的最小值
8 分组
group by
例: select 字段名 from 表名 group by 字段名;
通过某个字段 对表进行分组。
特别声明:文章来源用户上传并发布,本站只提供信息存储服务,不拥有所有权,内容仅供参考。