The objects that are acting differently. A WHERE clause acts on a table and a view, and a HAVING clause acts on a group.
Where is a filter on a table, and having is a filter on the result of the aggregation.
Sometimes having and where can achieve the same result, but priority is given to where.
Where the input row is selected before grouping and aggregation calculations (so that it controls which rows go into the aggregation calculation), and having the group selects the grouped rows after grouping and aggregating. Therefore, theWHERE clause cannot contain aggregate functions , because it makes no sense to attempt to use aggregate functions to determine which row input to the aggregation operation. Instead, the HAVING clause always contains a clustered function. (Strictly speaking, you can write a HAVING clause that doesn't use aggregation, but it's just a waste of effort.) The same conditions can be used more effectively in the WHERE phase. )
Having generally follows the group by, performing part of the record group selection to work.
Where is the execution of all data to work.
In addition, you can use aggregate functions such as having sum (qty) >1000
This article is from the "program ape of those Years" blog, please be sure to keep this source http://uyuyuuy.blog.51cto.com/6190986/1544140
MySQL where and have differences