This section describes aggregates (also described as set functions in ANSI SQL-92 and as column functions in some database literature).
Aggregates provide a means of evaluating an expression over a set of rows. Whereas the other built-in functions operate on a single expression, aggregates operate on a set of values and reduce them to a single scalar value. Built-in aggregates can calculate the minimum, maximum, sum, count, and average of an expression over a set of values as well as count rows.
In addition to the built-in aggregates, Derby allows you to create custom aggregate operators, called user-defined aggregates (UDAs). For information on creating and removing UDAs, see CREATE DERBY AGGREGATE statement and DROP DERBY AGGREGATE statement. See GRANT statement and REVOKE statement for information on usage privileges for UDAs.
For information on writing the Java classes that implement UDAs, see "Programming user-defined aggregates" in the Derby Developer's Guide.
The built-in aggregates can operate on expressions that evaluate to the data types shown in the following table.
-- not valid
SELECT MIN(flying_time), flight_id
FROM Flights
SELECT c1 FROM t1 GROUP BY c1 HAVING c2 > (SELECT t2.x FROM t2 WHERE t2.y = SUM(t1.c3))
A cursor declared on a ResultSet that includes an aggregate in the outer query block is not updatable.