17.10 - GROUP BY and Teradata-Specific Functions - Advanced SQL Engine - Teradata Database

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

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1145-171K
Language
English (United States)

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