GROUP BY and Teradata-Specific Functions - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
Language
English (United States)
Last Update
2024-04-03
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

For Teradata-specific functions, GROUP BY determines the partitions over which the function runs. The clause does not collapse all rows with the same value for the group-by columns into a single row. Thus, the GROUP BY clause in these cases need only specify the partitioning column for the function.

For example, the following statement computes the running sales for each store by using the GROUP BY clause to partition the data in sales_tbl by StoreID:

   SELECT StoreID, Sales, CSUM(Sales, StoreID)
   FROM sales_tbl 
   GROUP BY StoreID;

The results look like this:

   StoreID     Sales  CSum(Sales,StoreID)
   -------  --------  -------------------
      1001   1100.00              1100.00
      1001    400.00              1500.00
      1001   1000.00              2500.00
      1001   2000.00              4500.00
      1002    500.00               500.00
      1002   1500.00              2000.00
      1002   2500.00              4500.00
      1003   1000.00              1000.00
      1003   3000.00              4000.00