码迷,mamicode.com
首页 > 其他好文 > 详细

过滤分组where和having区别

时间:2015-02-28 23:02:54      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:mysql   group by   

聚集函数group by可以用来汇总数据,这使得我们可以对行精选计数,计算平均数,获得最大和最小值。

但是往往我们对于分组只需要选出特定条件的。

例子:select cust_id,count(*) as orders_count from orders where cust_id = "***" group by cust_id having order_count >= 2;

where和having是很多初学者容易搞混淆的,它们的区别:

where是过滤行的,在分组之前;

having是在分组之后,过滤分组的。



过滤分组where和having区别

标签:mysql   group by   

原文地址:http://blog.csdn.net/happy_cheng/article/details/43991833

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