Home > Database > Mysql Tutorial > How do we apply filtering conditions at the group level of the result set returned by MySQL?

How do we apply filtering conditions at the group level of the result set returned by MySQL?

王林
Release: 2023-09-17 21:45:03
forward
1043 people have browsed it

我们如何在 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 -

Example

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template