O'Reilly logo

MySQL 8 Cookbook by Karthik Appigatla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Filtering using HAVING

You can filter results of the GROUP BY clause by adding the HAVING clause.

For example, find the employees with an average salary of more than 140,000:

mysql>  SELECT emp_no, AVG(salary) AS avg FROM salaries GROUP BY emp_no HAVING avg > 140000 ORDER BY avg DESC;+--------+-------------+| emp_no | avg         |+--------+-------------+| 109334 | 141835.3333 || 205000 | 141064.6364 |+--------+-------------+2 rows in set (0.80 sec)

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required