Diff1 Function; Considerations For Diff1; Equivalent Result; Datetime Arguments - HP Neoview SQL Reference Manual

Hide thumbs Also See for Neoview SQL:
Table of Contents

Advertisement

DIFF1 Function

"Considerations for DIFF1"

"Examples of DIFF1"

The DIFF1 function is a sequence function that calculates the amount of change in an expression
from row to row in an intermediate result table ordered by a SEQUENCE BY clause in a SELECT
statement. See
DIFF1 is a Neoview SQL extension.
DIFF1 (column-expression-a [,column-expression-b])
column-expression-a
specifies a derived column determined by the evaluation of the column expression. If you
specify only one column as an argument, DIFF1 returns the difference between the value of
the column in the current row and its value in the previous row; this version calculates the
unit change in the value from row to row.
column-expression-b
specifies a derived column determined by the evaluation of the column expression. If you
specify two columns as arguments, DIFF1 returns the difference in consecutive values in
column-expression-a divided by the difference in consecutive values in
column-expression-b.
The purpose of the second argument is to distribute the amount of change from row to row
evenly over some unit of change (usually time) in another column.
Considerations for DIFF1

Equivalent Result

If you specify one argument, the result of DIFF1 is equivalent to:
column-expression-a - OFFSET(column-expression-a, 1)
If you specify two arguments, the result of DIFF1 is equivalent to:
DIFF1(column-expression-a) / DIFF1(column-expression-b)
The two-argument version involves division by the result of the DIFF1 function. To avoid
divide-by-zero errors, make sure that column-expression-b does not contain any duplicate
values whose DIFF1 computation could result in a divisor of zero.

Datetime Arguments

In general, Neoview SQL does not allow division by a value of INTERVAL data type. However,
to permit use of the two-argument version of DIFF1 with times and dates, Neoview SQL relaxes
this restriction and allows division by a value of INTERVAL data type.
Examples of DIFF1
Retrieve the difference between the I1 column in the current row and the I1 column in the
previous row:
SELECT DIFF1 (I1) AS DIFF1_I1
FROM mining.seqfcn
SEQUENCE BY TS;
DIFF1_I1
------------
-14461
334
SQL Functions and Expressions
"SEQUENCE BY Clause" (page
?
21959
-9116
7369
268).

Advertisement

Table of Contents
loading

Table of Contents