SUM (NoSQL query)
APPLIES TO:
NoSQL
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.
[
{
"name": "Cosmoxy pack",
"quantity": 35,
"category": "hiking-bags"
},
{
"name": "Heliont pack",
"category": "hiking-bags"
},
{
"name": "Immery bag",
"quantity": 15,
"category": "hiking-bags"
}
]
The SUM
function is used to sum the values of the quantity
field, when it exists, into a single aggregated value.
SELECT VALUE
SUM(p.quantity)
FROM
products p
WHERE
p.category = "hiking-bags"
[
50
]
Remarks
- 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.
Related content
Phản hồi
https://aka.ms/ContentUserFeedback.
Sắp ra mắt: Trong năm 2024, chúng tôi sẽ dần gỡ bỏ Sự cố với GitHub dưới dạng cơ chế phản hồi cho nội dung và thay thế bằng hệ thống phản hồi mới. Để biết thêm thông tin, hãy xem:Gửi và xem ý kiến phản hồi dành cho