Calculate the sum of the values within the requested window.

The SUM function works with numeric values and ignores NULL values.

For more information on usage, please refer to Window Functions.

Syntax

SUM([ DISTINCT ] <value> ) OVER ( [ PARTITION BY <partition_by> ] )

Parameters

ParameterDescriptionSupported input types
<value>The expression used for the SUM functionAny numeric type
<partition_by>An expression used for the PARTITION BY clauseAny

Return Types

NUMERIC

When DISTINCT is specified, duplicate values from <expression> are removed before calculating the sum.

Example

The example below shows how many players are on a specific level.

SELECT
	level,
	SUM(players) OVER (PARTITION BY level ) AS current_players
FROM
	players;

Returns:

levelcurrent_players
1156
2108
3127
4198
5207