TheHAVINGclause is used in SQL to filtergrouped resultsgenerated by the GROUP BY clause. Unlike WHERE, which filters individual rowsbeforegrouping, HAVING filtersafter aggregationhas been performed.
Example Usage:
sql
SELECT Department, AVG(Salary) AS AvgSalary
FROM Employees
GROUP BY Department
HAVING AVG(Salary) > 50000;
This query first groups employees by Department, calculates theaverage salary per department, and then filters onlythose departments where the average salary is greater than 50,000.
Why Other Options Are Incorrect:
Option A (REPLACE) (Incorrect):Used for string substitution, not filtering.
Option C (WITH) (Incorrect):Used inCommon Table Expressions (CTEs), not for filtering.
Option D (WHERE) (Incorrect):Used forrow-level filtering before aggregation, but itcannot be used on aggregate functions like SUM() or AVG().
Thus,HAVING is the correct answerfor filtering after grouping.
[Reference:SQL Aggregation and Grouping., ]
Contribute your Thoughts:
Chosen Answer:
This is a voting comment (?). You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Submit