WITH Clause Syntax | SQL SELECT Statements | Teradata Vantage - 17.05 - WITH Clause Syntax - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Data Manipulation Language

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
Release Date
January 2021
Content Type
Programming Reference
Publication ID
B035-1146-175K
Language
English (United States)
WITH expression_1 [,...] [ BY by_expr [,...] ] ] [...]

Syntax Elements

expression_1
An introduction to the condition to be fulfilled by the SELECT statement. Specifies a summary line, such as a total, for the values in a column of the select result. expression_1 can contain one or more aggregate expressions that are applied to column values.
You cannot include LOB columns in the WITH expression_1 list.
You cannot include a WITH clause with NORMALIZE.
by_expr
expression_2 [ ASC | DESC ]
expression_2
One or more result expressions for which expression_1 is provided. BY is valid only when used with WITH.
expression_2 can refer to an expression in the select expression list either by name or by means of a constant that specifies the numeric position of the expression in the expression list. It can also refer to a scalar subquery.
You cannot include LOB columns in the BY expression_2 list.
ASC
Results are to be ordered in ascending sort order.
If the sort field is a character string, the system orders it in ascending order according to the definition of the collation sequence for the current session.
The default order is ASC.
DESC
Results are to be ordered in descending sort order.
If the sort field is a character string, the system orders it in descending order according to the definition of the collation sequence for the current session.