Neoview SQL Reference Manual (R2.4)
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 “SEQUENCE BY Clause” (page 306).
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
condition includes the case in which both integer-expression and max-rows
are larger than the result table.
— The minimum of integer-expression and max-rows is out of range. In this
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).
• 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 TS
6215 TIMESTAMP ‘1950-03-05 08:32:09’
28174 TIMESTAMP ‘1951-02-15 14:35:49’
null TIMESTAMP ‘1955-05-18 08:40:10’
4597 TIMESTAMP ‘1960-09-19 14:40:39’
11966 TIMESTAMP ‘1964-05-01 16:41:02’
MOVINGAVG3
---------------------
6215
17194
17194
16385
8281
--- 5 row(s) selected.
408 SQL Functions and Expressions