HAVING in SQL

HOW TO USE HAVING CLAUSE 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.


Posted

in

Tags:

Comments

Leave a Reply