HOW TO USE HAVING CLAUSE IN SQL

HAVING in SQL

HAVING statement is used to filter the groups in result-set based on condition. HAVING clause is used after the GROUP BY clause. HAVING clause can include SQL aggregate functions in a query.

Syntax of HAVING Clause in SQL-

SELECT <column_name(s)>

FROM <table_name>

WHERE<condition>

GROUP BY<column_name(s)>

HAVING <condition>;

Example of HAVING Clause in SQL-

SELECT COUNT (CustomerID), Country

FROM Customers

GROUP BY Country

HAVING COUNT (CustomerID)>3

–This SQL statement will lists the number of customers in each country havng more than 3 customers.


Leave a Reply

Your email address will not be published. Required fields are marked *