RUNNING_SUM
Description
RUNNING_SUM returns the Sum of the previous rows. It is possible to specify a column based ordering and partitioning. Null values are skipped.
Syntax
RUNNING_SUM ( column [, ORDER BY ( sort_column [sorting], ... )] [, PARTITION BY ( partition_column, ... )] )
column: The source column where preceding rows are taken from.
sort_column: Optional sorting column to specify an order.
sorting: Each of these columns can have an optional tag specifying the ordering of the column. Default is ascending:
ASC: Ascending order
DESC: Descending order
partition_column: Optional partition column to specify groups in which
RUNNING_SUM
should operate.
Ordering
One or more columns can be given to specify an ordering. This tells the RUNNING_SUM
function what the preceding element actually is. Optionally every column can be tagged as ascending or descending.
Partitioning
The partition columns specify groups. The RUNNING_SUM
function operates independently within every group. This means when an ordering is given it is applied within every group.
Null handling
The RUNNING_SUM
for a NULL value is the same value as the RUNNING_SUM
value for the last non-NULL value.
Examples
[1] Simple example for Running Sum with Integer. | ||||||||||||||||
| ||||||||||||||||
|
[2] Simple example for Running Sum with Floats. | ||||||||||||||||
| ||||||||||||||||
|
[3] | ||||||||||||||||||||||
| ||||||||||||||||||||||
|
[4] | ||||||||||||||||||||||
| ||||||||||||||||||||||
|
[5] Simple example for Running Sum with null. | ||||||||||||||||||||||
| ||||||||||||||||||||||
|