The function of the where clause is to remove rows that do not meet the where conditions before grouping the query results, that is, filtering the data before grouping. The conditions cannot contain aggregation functions. Use where condition to display specific rows.
The function of the having clause is to filter the groups that meet the conditions, that is, filter the data after grouping. The conditions often include aggregation functions. Use the having condition to display specific groups, or multiple groupings can be used. Standard grouping.
The having clause is restricted to columns and aggregate expressions that have been defined in the SELECT statement. Typically, you need to reference aggregate values by repeating the aggregate function expression in the HAVING clause, just as you do in the SELECT statement.
For example:
SELECT A COUNT(B) FROM TABLE GROUP BY A HAVING COUNT(B)>2
Related recommendations: "SQL Tutorial"
The above is the detailed content of having usage. For more information, please follow other related articles on the PHP Chinese website!