TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

MySQL

MySQL GROUP BY HAVING clause

Overview

In this tutorial, we will learn MySQL GROUP BY HAVING clause. We can filter the aggregate information using the HAVING clause.

HAVING clause

The HAVING modifier can be used to require that the groups produced by a GROUP BY clause satisfy particular condition.The HAVING condition can refer to aggregate functions. The HAVING clause is appliedĀ  after GROUP BY and allows us to filter on the aggregate data that is not available to the WHERE clause.

WHERE vs HAVING

The WHERE clause is used to filter rows based on single row data. HAVING clause is used to filter based on aggregate data with GROUP BY clause.

The HAVING clause is evaluated after the grouping implied by the GROUP BY clause.

Syntax

The general syntax for the HAVING clause is as follows:

mysql> SELECT column_list, aggregate_function(column)
FROM <table_name>
GROUP BY grouping_column
HAVING <aggregate_condition> ;

Example

In this example, we will use the Continent table from the world MySQL database.

The following SQL query results in a list of the continents whose average of country population
is greater than 20,000,000.

We will the AVG() aggregate function to compute the average population.

mysql> SELECT Continent, AVG(population)
->FROM Country
->GROUP BY Continent
->HAVING AVG(Population) > 20000000;

 

+—————+—————–+
| Continent | AVG(population) |
+—————+—————–+
| Asia | 72647562.7451 |
| South America | 24698571.4286 |
+—————+—————–+
2 rows in set (0.00 sec)

 

MySQL GROUP BY HAVING Clause

 

—

MySQL Tutorials

MySQL Tutorials on this website:

https://www.testingdocs.com/mysql-tutorials-for-beginners/

For more information on MySQL Database:

https://www.mysql.com/

Related Posts

MySQL Workbench Windows 11

MySQL /

New MySQL Connection in Workbench

MySQL Command-line Client

MySQL /

Command-Line MySQL Client

Start MySQL Client

MySQL /

Start MySQL Client on Windows 11

Windows 11 Services Run Prompt

MySQL /

Start MySQL Server on Windows 11

MySQL Community Downloads TDocs

MySQL /

Download & Install MySQL on Windows 11

‹ MySQL GROUP BY ROLLUP Modifier› MySQL Temporal Functions

Recent Posts

  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Print Triangle Pattern Flowchart
  • RAPTOR Editions
  • Flowgorithm Conditional Breakpoint Statement
  • Flowgorithm Read Numbers from File Example
  • Search Text File Flowchart Example
  • Flowgorithm Turtle Graphics Symbols
  • Draw Circle using Flowgorithm Turtle

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version