3. Elements of SQL Statements : SQL Functions : Aggregate Functions : Restrictions on the Use of Aggregate Functions
 
Share this page                  
Restrictions on the Use of Aggregate Functions
The following restrictions apply to the use of aggregate functions:
Aggregate functions cannot be nested.
Aggregate functions can be used only in SELECT or HAVING clauses.
If a SELECT or HAVING clause contains an aggregate function, columns not specified in the aggregate must be specified in the GROUP BY clause. For example:
SELECT dept, AVG(emp_age)
FROM employee
GROUP BY dept;
The above SELECT statement specifies two columns, dept and emp_age, but only emp_age is referenced by the aggregate function, AVG. The dept column must be specified in the GROUP BY clause.