Home >Database >Mysql Tutorial >How do we apply filtering conditions at the group level of the result set returned by MySQL?
As we all know, the GROUP BY clause in the SELECT statement can group the result set returned by MySQL. Now, if we only want to return some specific groups, we need to apply the filter at the group level. This can be done by using the HAVING clause in the GROUP BY clause. The following example will demonstrate it -
Suppose we only want to return the group with an average salary of 55000, then we need to use the following filter conditions in the HAVING clause-
mysql> Select count(*),AVG(salary),Designation from employees GROUP BY designation having AVG(salary) = 55000; +----------+-------------+-------------+ | count(*) | AVG(salary) | Designation | +----------+-------------+-------------+ | 2 | 55000.0000 | Asst.Prof | +----------+-------------+-------------+ 1 row in set (0.00 sec)
The above is the detailed content of How do we apply filtering conditions at the group level of the result set returned by MySQL?. For more information, please follow other related articles on the PHP Chinese website!