Sequence By Clause; Considerations For Sequence By - HP Neoview SQL Reference Manual

Hide thumbs Also See for Neoview SQL:
Table of Contents

Advertisement

SEQUENCE BY Clause

"Considerations for SEQUENCE BY"

"Examples of SEQUENCE BY"
The SEQUENCE BY clause of the SELECT statement specifies the order in which to sort the rows
of the intermediate result table for calculating sequence functions. This option is used for
processing time-sequenced rows in data mining applications. See
SEQUENCE BY is a Neoview SQL extension.
SEQUENCE BY colname [ASC[ENDING] | DESC[ENDING]]
[,colname [ASC[ENDING] | DESC[ENDING]]]...
colname
names a column in select-list or a column in a table reference in the FROM clause of
the SELECT statement. colname is optionally qualified by a table, view, or correlation name;
for example, CUSTOMER.CITY.
ASC | DESC
specifies the sort order. ASC is the default. For ordering an intermediate result table on a
column that can contain null, nulls are considered equal to one another but greater than all
other nonnull values.
You must include a SEQUENCE BY clause if you include a sequence function in the select list
of the SELECT statement. Otherwise, Neoview SQL returns an error. Further, you cannot include
a SEQUENCE BY clause if there is no sequence function in the select list. See
(page
283).
Considerations for SEQUENCE BY
Sequence functions behave differently from set (or aggregate) functions and mathematical
(or scalar) functions.
If you include both SEQUENCE BY and GROUP BY clauses in the same SELECT statement,
the values of the sequence functions must be evaluated first and then become input for
aggregate functions in the statement.
— For a SELECT statement that contains both SEQUENCE BY and GROUP BY clauses,
you can nest the sequence function in the aggregate function:
SELECT ordernum,
FROM odetail
SEQUENCE BY partnum
GROUP BY ordernum;
— To use a sequence function as a grouping column, you must use a derived table for the
SEQUENCE BY query and use the derived column in the GROUP BY clause:
SELECT ordernum, movsum_qty, AVG(unit_price)
FROM
(SELECT ordernum, MOVINGSUM(qty_ordered, 3), unit_price
GROUP BY ordernum, movsum_qty;
— To use an aggregate function as the argument to a sequence function, you must also
use a derived table:
SELECT MOVINGSUM(avg_price,2)
FROM
(SELECT ordernum, AVG(unit_price)
268
SQL Clauses
MAX(MOVINGSUM(qty_ordered, 3)) AS maxmovsum_qty,
AVG(unit_price) AS avg_price
FROM odetail
SEQUENCE BY partnum)
AS tab2 (ordernum, movsum_qty, unit_price)
FROM odetail
GROUP BY ordernum)
"SELECT Statement" (page
"Sequence Functions"
141).

Advertisement

Table of Contents
loading

Table of Contents