The HAVING Clause is generally used along with the GROUP BY clause to apply more filters on the result-set.
Teradata HAVING example
The following SQL statement list the number of employee in each department. Only include those departments with more than 3 employees.
SELECT COUNT(EMP_ID),DEPARTMENT FROM TERADATAPOINT.EMPLOYEE GROUP BY DEPARTMENT HAVING COUNT(EMP_ID) >2;
GROUP BY clause cannot be used in WHERE clause. So HAVING is useful.
A SQL statement can have both the WHERE and HAVING clauses.
WHERE – filters the data before grouping.
HAVING – filters the data after grouping.