标签:
mysql 分组和聚合函数
Mysql 聚集函数有5个:
1、COUNT() 记录个数(count(1),count(*)统计表中行数,count(列名)统计列中非null数)
2、MAX() 最大值
3、MIN() 最小值
4、AVG()平均值
5、SUM() 求和
聚集函数常常和分组一起工作。
1、创建分组
select name, max(age) from stu group by name;
2、过滤分组
select name, max(age) from stu group by name having min(age) >10;
3、分组排序
select name, max(age) from stu group by name having min(age) >10 order by max(age) asc;
select name, max(age) from stu group by name having min(age) >10 order by max(age) desc limit 1,5;
标签:
原文地址:http://www.cnblogs.com/onlysun/p/4506135.html