Contents Aster SQL and Function Reference


Add to my manuals
228 Pages

advertisement

Contents Aster SQL and Function Reference | Manualzz

Window Function Order of Evaluation Aster Data proprietary and confidential

• a PARTITION BY clause whose partition_expression is used to group rows into partitions (rows that evaluate equally for this expression are considered a partition); and/or an ORDER BY clause whose order_expression provides the sorting criteria and whose

optional parameters such as ASC further specify the sorting behavior. See “ORDER BY

Clause in SELECT” on page V-80 for details. The default sorting behavior is “ASC

NULLS LAST”.

Window function behavior is defined largely by the PARTITION BY and ORDER BY clauses in the OVER clause, which group and sort the input rows consumed by the window function. A partition is defined as all the rows for which the PARTITION BY expression evaluates to the same value. Each partition is sorted according to the ORDER BY clause (if present). The window function is then computed over each partition, considering each row in order and returning an output value for each row. Because window functions are computed on a per-row basis, the number of rows is not changed by using a window function. The OVER clause does not determine the ordering of output rows.

Important!

Window functions themselves provide no guarantee of the ordering of output

rows. The ORDER BY subclause of the OVER clause does not determine the ordering of output rows. To sort output rows, the query must have a query-wide ORDER BY clause in

addition to those used in any window functions. For details, see “Window Function Example

4: Output Row Ordering” on page V-142 .

Certain subclauses of the OVER clause may be required or optional, depending on the type of window function you are using:

The PARTITION BY clause is optional, but using one is strongly recommended. If no

PARTITION BY clause is present, the entire input relation is considered to be one partition.

See the warning in

ORDER BY without PARTITION BY (page V-156) .

The ORDER BY clause is required if the function is a numbering window function, and

optional otherwise. See Numbering Window Functions (page V-139) .

If your window function is an aggregate window function, then the OVER clause can optionally include a ROWS or RANGE clause that defines a window frame (not shown in

the syntax synopsis above), as explained in “Window Frame Syntax” on page V-147 .

Window Function Order of Evaluation

From the point of view of the person querying the database, window functions are evaluated

after all filtering, grouping, and aggregation is done. This means that a window function can

refer to an aggregated value. (See “Window Function Example 15: ORDER BY SUM()” on page V-152 .) In fact, window functions may include any expression that may appear in the

SELECT clause except another window function. (That is, you may not nest window functions.)

Aster Database-supported window functions may be divided broadly into three categories:

numbering window functions, e.g., RANK(), DENSE_RANK(), and ROW_NUMBER()

aggregate window functions, e.g. AVG(), SUM(), COUNT(). All SQL aggregates supported

in Aster Database may be used as window functions. (See “Aggregate Functions” on page V-130 .)

lead/lag window functions, which take as input an expression evaluated at a specified offset ahead of or behind the current row, respectively.

V--138 Database SQL and Function Reference, version 4.6.2

aster data

advertisement

Was this manual useful for you? Yes No
Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Download PDF

advertisement

Table of contents