background image
<< Aggregates - set functions | ASIN function >>

ABS or ABSVAL function

<< Aggregates - set functions | ASIN function >>
Derby Reference Manual
112
· An
ORDER BY clause
(using an alias name) if the aggregate appears in the
result of the relevant query block. That is, an alias for an aggregate is permitted
in an
ORDER BY clause
if and only if the aggregate appears in a SelectItem in a
SelectExpression
.
All expressions in SelectItems in the
SelectExpression
must be either aggregates
or grouped columns (see
GROUP BY clause
). (The same is true if there is a
HAVING clause without a GROUP BY clause.) This is because the ResultSet of a
SelectExpression
must be either a scalar (single value) or a vector (multiple values),
but not a mixture of both. (Aggregates evaluate to a scalar value, and the reference to
a column can evaluate to a vector.) For example, the following query mixes scalar and
vector values and thus is not valid:
-- not valid
SELECT MIN(flying_time), flight_id
FROM Flights
Aggregates are not allowed on outer references (correlations). This means that if a
subquery contains an aggregate, that aggregate cannot evaluate an expression that
includes a reference to a column in the outer query block. For example, the following
query is not valid because SUM operates on a column from the outer query:
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.
Derby supports the following aggregates:
·
AVG function
·
COUNT function
·
MAX function
·
MIN function
·
SUM function
ABS or ABSVAL function
ABS or ABSVAL returns the absolute value of a numeric expression. The return type
is the type of parameter. All built-in numeric types are supported (
DECIMAL
,
DOUBLE
PRECISION
,
FLOAT
,
INTEGER
,
BIGINT
,
NUMERIC
,
REAL
, and
SMALLINT
).
Syntax
ABS(NumericExpression)
Example
-- returns 3
VALUES ABS(-3)
ACOS function
The ACOS function returns the arc cosine of a specified number.
The specified number is the cosine, in radians, of the angle that you want. The specified
number must be a
DOUBLE PRECISION
number.