使用order by对查询结果进行排序
- 语法
select 查询列表
from 表 【
where 筛选条件】
order by 排序列表 【asc | desc】;
select username, math order by math asc;
- 注意
asc ---- 升序,desc ---- 降序,不写默认升序
order by 子句中可以支持单个字段,多个字段,表达式,函数,别名
order by 放在select查询的语句末尾,limit字句除外
select * from xx where xx order by xx;
聚集函数
- 什么是聚集函数:Excel表格,求数量,求和,平均值,最大值,最小值
- 聚集函数操作的都是某一列的数据
- 聚集函数
count() ----求数量
select count(*) | count(列名) from 表;
----某一列数据行的总数
sum() ---- 求某一列数据的和,只对数值类型起作用
sum函数可以忽略null值
avg() ---- 求平均值
select avg(字段) from 表;
---- 某一列的平均值
max() ---- 最大值
min() ---- 最小值