You cannot use an aggregate expression in a condition
that is part of a WHERE clause unless you use the aggregate expression
within a subquery. You cannot apply an aggregate function to a BYTE
or TEXT column. For other general restrictions, see Subset of Expressions Valid in an Aggregate Expression.
An aggregate function returns one value for a set of queried
rows. The following examples show aggregate functions in SELECT statements:
SELECT SUM(total_price) FROM items WHERE order_num = 1013;
SELECT COUNT(*) FROM orders WHERE order_num = 1001;
SELECT MAX(LENGTH(fname) + LENGTH(lname)) FROM customer;
If you use an aggregate function and one or more columns
in the projection list of the Projection clause, you must include
all the column names that are not used as part of an aggregate or
time expression in the GROUP BY clause.