SQL/MP Reference Manual

HP NonStop SQL/MP Reference Manual523352-013
S-89
Example—SUBTOTAL_LABEL
Example—SUBTOTAL_LABEL
This command defines a subtotal label:
>> SET STYLE SUBTOTAL_LABEL "@";
SUM Function
SUM is a function that computes the sum of a set of numbers.
The type of the result depends on the type of the argument. If the argument is an exact
numeric type, the result is LARGEINT. If the argument type is FLOAT, REAL, or
DOUBLE PRECISION, the result is DOUBLE PRECISION.
The scale of the result is the same as the scale of the argument. If the argument has
no scale, the result is truncated.
[ ALL ] expression
specifies a numeric or INTERVAL expression that indicates the set of values to
sum.
The expression must include a value from each row of the result table (that is, at
least one column from the result table) and cannot include the COUNT, MAX, MIN,
or AVG functions, or another SUM function, as shown:
SUM (SALARY)
SUM (PARTCOST * QTY_ORDERED)
ALL is an optional keyword that does not change the meaning of the clause. SQL
uses all rows (whether or not you specify ALL) unless you use the DISTINCT
clause, described next.
DISTINCT column
specifies a set of distinct column values to average from each row of the result
table.The column cannot be a column from a view that corresponds to an
expression in the view definition.
If you specify DISTINCT in more than one SUM function in the same statement,
the functions must reference the same column.
Considerations—SUM
SUM is evaluated after eliminating all null values from the aggregate set. If the
result set is empty, SUM returns a null value.
SUM { ( [ ALL ] expression ) }
{ ( DISTINCT column ) }