Skip to content

Latest commit

 

History

History
59 lines (40 loc) · 1.61 KB

File metadata and controls

59 lines (40 loc) · 1.61 KB
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

SUM (NoSQL query)

[!INCLUDENoSQL]

Returns the sum of the values in the expression.

Syntax

SUM(<numeric_expr>)  

Arguments

Description
numeric_expr A numeric expression.

Return types

Returns a numeric expression.

Examples

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":::

Remarks

  • This function benefits from a range index.
  • If any arguments in SUM are string, boolean, or null; the entire aggregate system function returns undefined.
  • If any individual argument has an undefined value that value isn't included in the SUM calculation.

Related content