- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How can we apply filtering criteria at group levels of the result set returned by MySQL?
As we know that GROUP BY clause in a SELECT statement can divide the result set, returned by MySQL, in groups. Now if we want to return only some specific groups then need to apply filtering criteria at the group level. It can be done by using HAVING clause inside the GROUP BY clause. The example below will demonstrate it −
Suppose we want to return only the group which is having an average salary of 55000 then we need to use filtering criteria as follows in 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)
- Related Articles
- How can we divide the result set returned by MySQL into groups?
- GROUP BY the number of rows returned by GROUP BY in MySQL?
- In MySQL, how can we randomize set of rows or values in the result set?
- How can we get all the unique rows in MySQL result set?
- How can we handle a result set inside MySQL stored procedure?
- How can we get the summary output of a column in MySQL result set itself?
- How can we get only unique values of a column in MySQL result set?
- How can we specify the number of records to be returned in MySQL output?
- How can we create a MySQL view with GROUP BY clause?
- How Can MySQL operator precedence affect result set?
- What is the importance of the order of Columns in the SET clause of UPDATE statement? Will it make big difference in result set returned by MySQL?
- Can we replace a number with a String in a MySQL result set?
- How can we apply BIT_LENGTH() function on the column/s of MySQL table?
- How can we use SET statement to assign a SELECT result to a MySQL user variable?
- How can we change MySQL user password by using the SET PASSWORD statement?