码迷,mamicode.com
首页 > 数据库 > 详细

Mysql 聚集函数和分组

时间:2015-03-03 20:13:01      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:

Mysql 聚集函数有5个:

1、COUNT() 记录个数

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/nzbbody/p/4311724.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!