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

SQL Functions, Expressions, and Predicates

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Published
July 2021
Language
English (United States)
Last Update
2021-07-28
dita:mapPath
SQL_Functions__Expressions__and_Predicates.Upload_071421/djk1612415574830.ditamap
dita:ditavalPath
SQL_Functions__Expressions__and_Predicates.Upload_071421/wrg1590696035526.ditaval
dita:id
B035-1145
lifecycle
previous
Product Category
Teradata Vantageā„¢

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