Example: Cumulative Minimum - Advanced SQL Engine - Teradata Database

SQL Functions, Expressions, and Predicates

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-30
dita:mapPath
tpt1555966086716.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1145
lifecycle
previous
Product Category
Teradata Vantageā„¢

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

   SELECT city, kind, sales, week, 
   MIN(sales) OVER (PARTITION BY city, kind
                    ORDER BY week 
                    ROWS UNBOUNDED PRECEDING) 
   FROM activity_month;
   
   city     kind      sales  week  Cumulative Min(sales)
   -------  --------  -----  ----  ---------------------
   LA       Canvas      263    16                    263
   LA       Canvas      294    17                    263
   LA       Canvas      321    18                    263
   LA       Canvas      274    20                    263
   LA       Leather     144    16                    144
   LA       Leather     826    17                    144
   LA       Leather     489    20                    144
   LA       Leather     555    21                    144
   Seattle  Canvas      100    16                    100
   Seattle  Canvas      182    17                    100
   Seattle  Canvas       94    18                     94
   Seattle  Leather     933    16                    933
   Seattle  Leather     840    17                    840
   Seattle  Leather     899    18                    840
   Seattle  Leather     915    19                    840
   Seattle  Leather     462    20                    462