Difference Introduction:
The action of the WHERE clause is to remove rows that do not conform to the where condition before grouping the query results, that is, to filter the data before the group, where the cluster function cannot be included, and the Where condition to filter out a particular row.
The HAVING clause is used to filter the groups that meet the criteria, that is, to filter the data after grouping, often including the clustering function, using the having condition to filter out specific groups, or multiple grouping criteria for grouping.
Attention:
1. The HAVING clause must precede the order by after group by.
2. The WHERE statement precedes the group BY statement, and SQL calculates the where statement before grouping.
3. The having statement is after the group by statement, and SQL calculates the having statement after grouping.
Example:
Select category, sum (quantity) as quantity and from A Group by category having sum (quantity) > 18
Example: joint use of having and where
Select category, sum (quantity) from A where quantity > 8 Group by Category having SUM (quantity) > 10
Summarize
The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring certain help, if you have questions you can message exchange.