GROUP BY and Teradata-Specific Functions

Teradata Vantageā„¢ SQL Functions, Expressions, and Predicates

brand
Software
Teradata Vantage
prodname
Teradata Database
Teradata Vantage NewSQL Engine
vrm_release
16.20
category
Programming Reference
featnum
B035-1145-162K

For Teradata-specific functions, GROUP BY determines the partitions over which the function executes. 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