Nesting Aggregates - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
ft:locale
en-US
ft:lastEdition
2024-12-11
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

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;