TOP Function Syntax | Teradata Vantage - TOP - Advanced SQL Engine - Teradata Database

Time Series Tables and Operations

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Published
July 2021
Language
English (United States)
Last Update
2021-07-28
dita:mapPath
zzg1600277315070.ditamap
dita:ditavalPath
zzg1600277315070.ditaval
dita:id
B035-1208
lifecycle
previous
Product Category
Teradata Vantageā„¢

Returns the largest number_of_values in the value_expression for each group, with or without ties. TOP is a single-threaded function.

To invoke the time series version of this function, use the GROUP BY TIME clause. For more information, see GROUP BY TIME Clause.

Syntax

TOP [ WITH TIES ] ('number_of_values', 'value_expression')

Syntax Elements

number_of_values
Teradata integer value representing the number of values to return.
value_expression
A literal or column expression from which the top values are taken.

The value_expression cannot be a reference to a view column derived from a function, and cannot contain any ordered analytical or aggregate functions.

Return Value

The return value is the same as the input data type.

Nulls are not included in the computation.

Usage Notes

TOP is valid only for numeric data.

WITH TIES implies the rows returned by the query include the specified number of rows in the ordered set for each time bucket, plus any additional rows where the sort key value is the same as the value of the sort key in the last row satisfying the specified number or percentage of rows. If this clause is omitted and ties are found, the earliest value in terms of timecode is returned.