HAVING clause in SQL


The previous article Taimienphi.vn introduced you to the GROUP BY clause in SQL. The GROUP BY clause in SQL is used with the Group function to retrieve data grouped in one or more columns, what about the HAVING clause in SQL?


To learn HAVING clause in SQL What is it, how is it used? Read along to the article below of Taimienphi.vn offline.

The HAVING clause in SQL is used to filter data based on Group functions. The HAVING clause in SQL is similar to the WHERE clause but is used with Group functions.

The Group function is not used in the WHERE clause but is used in the HAVING clause in SQL.

Example of HAVING clause in SQL

If you want to select parts of the company with a total salary of more than 25,000 employees, the SQL query will look like this:

SELECT dept, SUM (salary)

FROM employee

GROUP BY dept

HAVING SUM (salary)> 25000

Some notes with the HAVING clause in SQL

When the WHERE and GROUP BY clauses in SQL and HAVING are used together in the SELECT statement, the WHERE clause will be processed first, then the rows returned after the WHERE clause will be executed. grouped based on the GROUP BY clause.

Finally, any condition of the Group function in the HAVING clause in SQL must be applied to grouped rows before the final output is displayed.

https://thuthuat.taimienphi.vn/having-in-sql-33473n.aspx
Thus, the article on Taimienphi.vn has just introduced you to the HAVING clause in SQL. In the next section, Taimienphi.vn will introduce you more about clauses, NOT IN operator, LIKE IN comparison operator in SQL, …

.

Add a Comment

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