There's more...

There are some OLAP functions that we can use, such as:

  • Cumulative sum (CSUM): It computes a running or cumulative total of a column’s value. Consider the following example code block:
/*CSUM select*/SELECT EMP_ID , CSUM(SALARY,EMP_ID) FROM EMP_SAL;

CSUM(COLUMN_1) will result in an error as CSUM needs two columns as arguments. The first column is used for sorting the sequence and the second column is then used to perform the cumulative sum. Check the code for syntax for CSUM:

/*Syntax for CSUM*/CSUM(columnname,sortlist)
  • Moving Average (MAVG): Used to calculate the moving average on a column. The number of rows used for the aggregation operation is called as query width, as shown in the code:
/*MAVG*/SELECT EMP_ID,SAL, ...

Get Teradata Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.