Having Clause:
The Having clause is used to filter the group result. As we cannot use Where to filter the Group By clause results so Having provide the same functionality as Where. It filter the result fetched by Group By clause. It comes after Group By clause in a query and before Order By clause.
Syntax:
SELECT columname(s) FROM tablename WHERE (conditions) GROUP BY columname(s) HAVING (conditions) ORDER BY columname(s) ASC | DESC;
Example:
SELECT Name, City FROM Employee GROUP BY City HAVING AVG(Salary) >= 10000;
The above example will group the result-set by City wise and fetch those records whose average salary is greater than or equal to 10000.
0 Comment(s)