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.
Syntax#
[ HAVING <search condition> ]
Arguments#
<search_condition> Specifies one or more predicates for groups and/or aggregates to meet. For more information about predicates, see Predicates.
The text, image, and ntext data types cannot be used in a HAVING clause.
Examples#
The following example that uses a simple HAVING clause retrieves the total for each SalesOrderID from the SalesOrderDetail table that exceeds $100000.00.
USE AdventureWorks2012 ;
SELECT SalesOrderID, SUM(LineTotal) AS SubTotal
FROM Sales.SalesOrderDetail
GROUP BY SalesOrderID
HAVING SUM(LineTotal) > 100000.00
ORDER BY SalesOrderID ;