Movingavg Function; Example Of Movingavg - HP Neoview SQL Reference Manual

Hide thumbs Also See for Neoview SQL:
Table of Contents

Advertisement

MOVINGAVG Function

The MOVINGAVG function is a sequence function that returns the average of nonnull values
of a column in the current window of an intermediate result table ordered by a SEQUENCE BY
clause in a SELECT statement. See
MOVINGAVG is a Neoview SQL extension.
MOVINGAVG (column-expression,integer-expression [,max-rows])
column-expression
specifies a derived column determined by the evaluation of the column expression.
integer-expression
is an SQL numeric value expression of signed data type SMALLINT or INTEGER that specifies
the current window. The current window is defined as the current row and the previous
(integer-expression - 1) rows.
max-rows
is an SQL numeric value expression of signed data type SMALLINT or INTEGER that specifies
the maximum number of rows in the current window.
Note these considerations for the window size:
The actual value for the window size is the minimum of integer-expression and
max-rows.
If these conditions are met, MOVINGAVG returns the same result as RUNNINGAVG:
— The integer-expression is out of range, and max-rows is not specified. This
— The minimum of integer-expression and max-rows is out of range. In this
The number of rows is out of range if it is larger than the size of the result table, negative,
or NULL.

Example of MOVINGAVG

Return the average of nonnull values of a column in the current window of three rows:
create table db.mining.seqfcn (I1 integer, ts timestamp);
SELECT MOVINGAVG (I1,3) AS MOVINGAVG3
FROM mining.seqfcn
SEQUENCE BY TS;
I1
6215
28174
null
4597
11966
MOVINGAVG3
---------------------
--- 5 row(s) selected.
condition includes the case in which both integer-expression and max-rows
are larger than the result table.
case, integer-expression could be within range, but max-rows might be the
minimum value of the two and be out of range (for example, a negative number).
TS
TIMESTAMP '1950-03-05 08:32:09'
TIMESTAMP '1951-02-15 14:35:49'
TIMESTAMP '1955-05-18 08:40:10'
TIMESTAMP '1960-09-19 14:40:39'
TIMESTAMP '1964-05-01 16:41:02'
6215
17194
17194
16385
8281
"SEQUENCE BY Clause" (page
268).
MOVINGAVG Function
367

Advertisement

Table of Contents
loading

Table of Contents