Example: Cumulative Maximum - 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ā„¢

The following SQL query might yield the results that follow it, where the cumulative maximum value for sales is returned for each partition defined by city and kind.

   SELECT city, kind, sales, week, 
   MAX(sales) OVER (PARTITION BY city, kind 
                    ORDER BY week ROWS UNBOUNDED PRECEDING)
   FROM activity_month;

Result:

   city     kind      sales  week  Cumulative Max(sales)
   -------  --------  -----  ----  ---------------------
   LA       Canvas      263    16                    263
   LA       Canvas      294    17                    294
   LA       Canvas      321    18                    321
   LA       Canvas      274    20                    321
   LA       Leather     144    16                    144
   LA       Leather     826    17                    826
   LA       Leather     489    20                    826
   LA       Leather     555    21                    826
   Seattle  Canvas      100    16                    100
   Seattle  Canvas      182    17                    182
   Seattle  Canvas       94    18                    182
   Seattle  Leather     933    16                    933
   Seattle  Leather     840    17                    933
   Seattle  Leather     899    18                    933
   Seattle  Leather     915    19                    933
   Seattle  Leather     462    20                    933