title | titleSuffix | description | author | ms.author | ms.reviewer | ms.service | ms.subservice | ms.topic | ms.devlang | ms.date | ms.custom |
---|---|---|---|---|---|---|---|---|---|---|---|
SUM |
Azure Cosmos DB for NoSQL |
An Azure Cosmos DB for NoSQL system function that sums the specified values. |
jcodella |
jacodel |
sidandrews |
cosmos-db |
nosql |
reference |
nosql |
02/27/2024 |
query-reference |
[!INCLUDENoSQL]
Returns the sum of the values in the expression.
SUM(<numeric_expr>)
Description | |
---|---|
numeric_expr |
A numeric expression. |
Returns a numeric expression.
For this example, consider a container with multiple items that may contain a quantity
field.
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/sum/seed.json" range="1-2,4-8,10-13,15-19" highlight="4,13":::
The SUM
function is used to sum the values of the quantity
field, when it exists, into a single aggregated value.
:::code language="nosql" source="~/cosmos-db-nosql-query-samples/scripts/sum/query.sql" highlight="2":::
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/sum/result.json":::
- This function benefits from a range index.
- If any arguments in
SUM
are string, boolean, or null; the entire aggregate system function returnsundefined
. - If any individual argument has an
undefined
value that value isn't included in theSUM
calculation.