Nota
L-aċċess għal din il-paġna jeħtieġ l-awtorizzazzjoni. Tista’ tipprova tidħol jew tibdel id-direttorji.
L-aċċess għal din il-paġna jeħtieġ l-awtorizzazzjoni. Tista’ tipprova tibdel id-direttorji.
The SUM function calculates the sum of the values in the expression.
Syntax
SUM(<numeric_expr>)
Arguments
| Description | |
|---|---|
numeric_expr |
A numeric expression to sum. |
Return types
Returns a numeric scalar value.
Examples
This section contains examples of how to use this query language construct.
Consider this sample set of documents within the Products collection for these examples.
[
{
"name": "Sathem Backpack",
"quantity": 0,
"detailCategory": "gear-hike-backpacks"
},
{
"name": "Ventrin Backpack",
"quantity": 230,
"detailCategory": "gear-hike-backpacks"
},
{
"name": "Martox Backpack",
"quantity": 14,
"detailCategory": "gear-hike-backpacks"
},
{
"name": "Rangeo Backpack",
"quantity": 232,
"detailCategory": "gear-hike-backpacks"
},
{
"name": "Moonroq Backpack",
"quantity": 141,
"detailCategory": "gear-hike-backpacks"
}
]
Sum values for a single property
In this example, the SUM function is used to sum the values of the quantity property into a single aggregated value.
SELECT VALUE
SUM(p.quantity)
FROM
products p
WHERE
p.detailCategory = "gear-hike-backpacks"
[
617
]
Remarks
- This function benefits from the use of a range index. For more information, see range indexes.
- If any arguments in
SUMare string, boolean, or null; the entire aggregate system function returnsundefined. - If any individual argument has an
undefinedvalue, that value isn't included in theSUMcalculation.