Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 12.0.1 » SQL Anywhere Server - SQL Usage » Query and modify data » Summarizing, grouping, and sorting query results » Aggregate functions that summarize query results


Where you can use aggregate functions

The aggregate functions can be used in a SELECT list, as in the previous examples, or in the HAVING clause of a select statement that includes a GROUP BY clause.

You cannot use aggregate functions in a WHERE clause or in a JOIN condition. However, a SELECT statement with aggregate functions in its SELECT list often includes a WHERE clause that restricts the rows to which the aggregate is applied.

If a SELECT statement includes a WHERE clause, but not a GROUP BY clause, an aggregate function produces a single value for the subset of rows that the WHERE clause specifies.

Whenever an aggregate function is used in a SELECT statement that does not include a GROUP BY clause, it produces a single value. This is true whether it is operating on all the rows in a table or on a subset of rows defined by a where clause.

You can use more than one aggregate function in the same SELECT list, and produce more than one scalar aggregate in a single SELECT statement.

 Aggregate functions and outer references
 See also