17.10 - Nesting Aggregates - Advanced SQL Engine - Teradata Database

Teradata Vantageā„¢ - SQL Functions, Expressions, and Predicates

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Published
July 2021
Language
English (United States)
Last Update
2021-07-28
dita:mapPath
SQL_Functions__Expressions__and_Predicates.Upload_071421/djk1612415574830.ditamap
dita:ditavalPath
SQL_Functions__Expressions__and_Predicates.Upload_071421/wrg1590696035526.ditaval
dita:id
kby1472250656485

Aggregate operations cannot be nested. The following aggregate is not valid and returns an error:

   AVG(MAXIMUM (Salary)) 

Although direct nesting of aggregates is not supported, nested aggregates can be evaluated using a derived table that contains the aggregates to be nested. For more information, see Teradata Vantageā„¢ - Time Series Tables and Operations, B035-1208.

Also, aggregates can be nested in aggregate window functions. The following statement is valid and includes an aggregate SUM function nested in a RANK window function:

   SELECT region
      ,product
      ,SUM(amount) 
      ,RANK() OVER (PARTITION BY region ORDER by SUM (amount))
   FROM table;