The HAVING clause is used in combination with the GROUP BY clause. It can be used in a SELECT statement to filter the records that a GROUP BY returns.
譯:HAVING子句是與GROUP BY子句聯合使用。能夠用於SELECT語句中用於篩選由GROUP BY返回的結果。
The syntax for the HAVING clause is:
SELECT column1, column2, ... column_n, aggregate_function (expression)
FROM tables
WHERE predicates
GROUP BY column1, column2, ... column_n
HAVING condition1 ... condition_n;aggregate_function can be a function such as
SUM,
COUNT,
MIN, or
MAX.
譯:
aggregate_function可以是
SUM,
COUNT,
MIN, or
MAX函數。
Example using the SUM functionFor example, you could also use the SUM function to return the name of the department and the total