Usage Notes - Teradata Database

SQL Data Manipulation Language

Product
Teradata Database
Release Number
15.10
Language
English (United States)
Last Update
2018-10-06
dita:id
B035-1146
lifecycle
previous
Product Category
Teradata® Database

GROUP BY Clause Terminology

A GROUP BY clause is said to be simple if it does not contain any of the following elements:

  • rollup_list
  • cube_list
  • grouping_sets_specification
  • A GROUP BY clause is said to be primitive if it does not contain any of the following elements:

  • rollup_list
  • cube_list
  • grouping_sets_specification
  • a grouping_expression and an empty_grouping_set.
  • See “GROUPING SETS Option” on page 139 for definitions of rollup_list, cube_list, grouping_sets_specification, and empty_grouping_set.

    See the following topics for examples of non‑simple, non‑primitive GROUP BY clauses:

  • “ROLLUP Grouping Set Option” on page 142
  • “CUBE Grouping Set Option” on page 136
  • “GROUPING SETS Option” on page 139
  • The following table provides the definitions for the valid ordinary grouping set expressions you can specify in a GROUP BY clause.

     

    Ordinary Grouping Set Expression

                                                            Definition

    column_name

    a set of column names drawn from the list of tables specified in the FROM clause of the SELECT statement that is used in the GROUP BY clause to specify the columns by which data is to be grouped.

    The maximum number of columns you can specify is 64.

    You cannot include LOB columns in the grouping expression.

    You can specify a column_name_alias instead of column_name as long as it does not have the same name as a physical column in the table definition. In this case, you must specify column_position, not column_name_alias.

    column_position

    the sequential numeric position of columns within the column_list clause of the SELECT statement that is used in the GROUP BY clause to specify the order by which data is to be grouped.

    The value you specify must be a positive constant integer literal with a value between 1 and the number of columns specified in the select list, inclusive. Note that Teradata Database treats macro and procedure parameters as expressions, not as the specification of a column position.

    You cannot include LOB columns in the grouping expression.

    This is a Teradata extension to the ANSI SQL:2011 standard.

    column_expression

    any list of valid SQL expressions specified for the GROUP BY clause.

    You can specify column_name, column_position, and expression either as single entries or as a list.

    You can specify a scalar subquery as an ordinary grouping set expression.

    You can also specify a scalar UDF as an ordinary grouping set expression.

    You cannot include LOB columns in the ordinary grouping set.

    Use of column_expression is a Teradata extension to the ANSI SQL:2011 standard.