Home  >  Article  >  Database  >  MySQL分组数据_MySQL

MySQL分组数据_MySQL

WBOY
WBOYOriginal
2016-06-01 13:06:441049browse

分组

理解分组可以看如下一个例子,首先我们打印出products表如下

从上面的表中可以看出,每个vendor都有若干个产品,那么怎么一次统计每个vendor有多少个产品呢? 这里就可以使用GROUP BY,如下

如果不使用group by,那么结果就是统计有多少行了:

分组过滤

分组过滤也就是多统计后的数据再进行过滤,如上面的例子中,统计出来了每一个vendor有多个产品,那么可以使用HAVING来过滤出 产品数量多于3个的vendor:

WHERE 语句可以喝HAVING语句一起灵和使用,如需要找出,有2种以上的产品价格大于10:

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn