The HAVING clause is used in combination with the GROUP BY clause and the SQL aggregate functions. HAVING clause allows us to call the data conditionally on the column that return from using the SQL aggregate functions.

The SQL HAVING syntax is simple and looks like this:

SELECT [COLUMN NAME 1] , AGGREGATE FUNCTION ( [COLUMN NAME 2] )
FROM [TABLE NAME]
GROUP BY[COLUMN NAME 1]
HAVING AGGREGATE FUNCTION ( [COLUMN NAME 2] ) = [CONDITION]


EXAMPLE :

Let�s say, we want to get the departments from GameScores that total scores is more than 4000.

Table GameScores

PlayerNameDepartmentScores
JasonIT3000
IreneIT1500
JaneMarketing1000
DavidMarketing2500
PaulHR2000
JamesHR2000

SQL statement :

SELECT Department, SUM(Scores)
FROM GameScores
GROUP BY Department
HAVING SUM(Scores)>4000

Result:

DepartmentSUM(Scores)
IT4500