- 别名查询: select 字段名1 as 别名 , 字段名2 as 别名... from 表名 as 表别名;
- 清除重复值:select distinct 字段名 from 表名;
- 聚合函数: count() : 计数 sum() : 求和 max() : 求最大值 min() : 求最小值 avg() : 求平均值 分组 group by 字段:
- select * from 表名 where 条件 group by 分组字段 【having 分组条件】;
- having 和 where 的区别: having是在分组后对数据进行过滤
where是在分组前对数据进行过滤
having后面可以使用聚合函数
where后面不可以使用聚合函数
分页:
select * from 表名 limit 起始数,查询几条;
数据库语句查询顺序:
select distinct * 或者字段或者聚合 from 表名 where 条件 and 条件 或
btween 条件 或 or 条件 或 in 条件 group by 字段 having 条件 order by 字段 asc/desc limit a,b