首页 > 数据库技术 > 详细

mysql 分组和聚合函数

时间:2015-05-15 17:06:45      阅读:292      评论:0      收藏:0      [点我收藏+]

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;

mysql 分组和聚合函数

原文:http://www.cnblogs.com/onlysun/p/4506135.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!