Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
35 views

SQL HAVING Clause Example

The HAVING clause is used to filter data based on group functions and is similar to a WHERE clause but for grouped data. Group functions like SUM cannot be used in a WHERE clause but can be used in HAVING to filter groups. The HAVING clause is applied after rows are grouped by the GROUP BY clause to display only groups matching the HAVING condition.

Uploaded by

venniiii
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

SQL HAVING Clause Example

The HAVING clause is used to filter data based on group functions and is similar to a WHERE clause but for grouped data. Group functions like SUM cannot be used in a WHERE clause but can be used in HAVING to filter groups. The HAVING clause is applied after rows are grouped by the GROUP BY clause to display only groups matching the HAVING condition.

Uploaded by

venniiii
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

SQL HAVING Clause

Having clause is used to filter data based on the group functions. This is similar to WHERE condition but is used with group functions. Group functions cannot be used in WHERE Clause but can be used in HAVING clause.

SQL HAVING Clause Example


If you want to select the department that has total salary paid for its employees more than 25000, the sql query would be like;

SELECT FROM GROUP HAVING SUM (salary) > 25000


The output would be like:

dept,

SUM

(salary) employee

BY

dept

dept ------------Electronics Aeronautics InfoTech ------------55000 35000 30000

salary

When WHERE, GROUP BY and HAVING clauses are used together in a SELECT statement, the WHERE clause is processed first, then the rows that are returned after the WHERE clause is executed are grouped based on the GROUP BY clause. Finally, any conditions on the group functions in the HAVING clause are applied to the grouped rows before the final output is displayed.

You might also like