The SQL HAVING is a clause that enables conditions at the aggregate level. It is used instead of the WHERE clause when Aggregate Functions are used.
The SQL HAVING clause supports the same operators as the WHERE clause. Grouped results can be checked using this clause.
The HAVING clause is used to SELECT information based aggregate information. For example, one may want to list sales representatives that have sales totaling over $10,000. This is very useful for analytical reporting.
SQL HAVING is used as follows.
SQL HAVING Syntax
SQL HAVING Example
The following example regions from the branch table that have total employee_count greater than 5.
Here are the contents of the table:
Table: BRANCH
branch_nbr | branch_name | region_nbr | employee_count |
108 | New York | 100 | 10 |
110 | Boston | 100 | 6 |
212 | Chicago | 200 | 5 |
404 | San Diego | 400 | 6 |
415 | San Jose | 400 | 3 |
This SQL Statement with HAVING is executed:
Here is the result.
region_nbr | sum(employee_count) |
100 | 16 |
400 | 9 |
Advertisements:
Infogoal.com is organized to help you gain mastery.
Examples may be simplified to facilitate learning.
Content is reviewed for errors but is not warranted to be 100% correct.
In order to use this site, you must read and agree to the
terms of use, privacy policy and cookie policy.
Copyright 2006-2020 by Infogoal, LLC. All Rights Reserved.