Window Aggregate Functions - Analytics Database - Teradata Vantage

SQL Functions, Expressions, and Predicates

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2024-01-12
dita:mapPath
obm1628111499646.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
kby1472250656485
lifecycle
latest
Product Category
Teradata Vantageā„¢

An aggregate function on which a window specification is applied is called a window aggregate function. Without a window specification, aggregate functions return one value for all qualified rows examined. Window aggregate functions return a new value for each of the qualifying rows participating in the query.

Thus, the following SELECT statement, which includes the aggregate AVG, returns one value only: the average of sales.

   SELECT AVG(sale) 
   FROM monthly_sales;

Result:

   Average(sale)
   -------------
            1368

The AVG window function retains each qualifying row.

The following SELECT statement might return the results that follow.

   SELECT territory, smonth, sales,
   AVG(sales) OVER (PARTITION BY territory 
                    ORDER BY smonth ROWS 2 PRECEDING)
   FROM sales_history;

Result:

   territory  smonth   sales  Moving Avg(sales)
   ---------  -------  -----  -----------------
   East        199810     10                 10
   East        199811      4                  7
   East        199812     10                  8
   East        199901      7                  7
   East        199902     10                  9
   West        199810      8                  8
   West        199811     12                 10
   West        199812      7                  9
   West        199901     11                 10
   West        199902      6                  8