RANK Function Syntax (ANSI) | Teradata Vantage - RANK Function Syntax (ANSI) - Advanced SQL Engine - Teradata Database

SQL Functions, Expressions, and Predicates

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-30
dita:mapPath
tpt1555966086716.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1145
lifecycle
previous
Product Category
Teradata Vantage™
RANK() OVER (
  [ PARTITION BY column_reference [,...] ]
  ORDER BY value_spec [,...]
  [ RESET WHEN condition ]
  [ WITH TIES { LOW | HIGH | AVG | DENSE } ]
)

Syntax Elements

OVER
Specifies how values are grouped, ordered, and considered when computing the cumulative, group, or moving function.
Values are grouped according to the PARTITION BY BEGIN and RESET WHEN clauses END, sorted according to the ORDER BY clause, and considered according to the aggregation group within the partition.
PARTITION BY column_reference [,...]
The group or groups over which the function operates.
If there is no PARTITION BY or RESET WHEN clauses, then the entire result set, delivered by the FROM clause, constitutes a partition.
PARTITION BY clause is also called the window partition clause.
ORDER BY
The order in which the values in a group or partition are sorted.
value_spec
value_expression [ ASC | DESC ] [ NULLS { FIRST | LAST } ]
RESET WHEN
The group, or groups, over which the function operates, depending on the evaluation of the specified condition. If the condition evaluates to TRUE, a new dynamic partition is created inside the specified window partition.
If there is no PARTITION BY or RESET WHEN clauses, then the entire result set, delivered by the FROM clause, constitutes a partition.
condition
A conditional expression used to determine conditional partitioning. The condition in the RESET WHEN clause is equivalent in scope to the condition in a QUALIFY clause with the additional constraint that nested ordered analytical functions cannot specify a RESET WHEN clause. In addition, you cannot specify SELECT as a nested subquery within the condition.
The condition is applied to the rows in all designated window partitions to create sub-partitions within the particular window partitions.
For more information, see “RESET WHEN Condition Rules” and the “QUALIFY Clause” in Teradata Vantage™ - SQL Data Manipulation Language, B035-1146.
WITH TIES
Specifies the rank for all ties:
Option Description
LOW All ties get lowest rank. Returns integer data type.
HIGH All ties get highest rank. Returns integer data type.
AVG All ties get average rank. Returns decimal data type.
DENSE All ties are ranked as DENSE_RANK ranks them. Returns integer data type.
ASC
Ascending sort order.
DESC
Descending sort order.
NULLS FIRST
NULL results are to be listed first.
NULLS LAST
NULL results are to be listed last.