Skip to main content

SELECT Having

Specifies a search condition for a group or an aggregate. HAVING can be used only with the SELECT statement. HAVING is typically used with a GROUP BY clause. When GROUP BY is not used, there is an implicit single, aggregated group.

bSQL Syntax Conventions

Syntax

[ HAVING <search condition> ]  

Arguments

\<search_condition> Specifies one or more predicates for groups and/or aggregates to meet.

<search_condition> ::= 
{ ( <search_condition> ) }
[ { AND | OR } { <predicate> | ( <search_condition> ) } ]
[ ,...n ]

<predicate> ::=
{ expression { = | ! = | > | > = | < | < = } expression
| ISNULL(expression)
| ~ "regex_expression"

Examples

The following example uses the HAVING clause to specify which of the groups generated in the GROUP BY clause should be included in the result set.

SELECT c.sector, COUNT(*) AS count, SUM(p.price) AS totalprice  
FROM pricing AS p
JOIN companies AS c
ON c.symbol = p.symbol
GROUP BY c.sector
HAVING SUM(p.price) > 10000

See Also