ARRAY_SUM
Descriptionβ
Calculates the sum of all elements in an array
Syntaxβ
ARRAY_SUM(<src>)
Parametersβ
Parameter | Description |
---|---|
<src> | Corresponding array |
Return Valueβ
Returns the sum of all elements in the array. NULL values in the array will be skipped. For an empty array or an array with all NULL values, the result returns a NULL value.
Exampleβ
SELECT ARRAY_SUM([1, 2, 3, 6]),ARRAY_SUM([1, 4, 3, 5, NULL]),ARRAY_SUM([NULL]);
+-------------------------+-------------------------------+-------------------------------------------+
| array_sum([1, 2, 3, 6]) | array_sum([1, 4, 3, 5, NULL]) | array_sum(cast([NULL] as ARRAY<BOOLEAN>)) |
+-------------------------+-------------------------------+-------------------------------------------+
| 12 | 13 | NULL |
+-------------------------+-------------------------------+-------------------------------------------+