42 lines
824 B
Plaintext
42 lines
824 B
Plaintext
[discrete]
|
|
[[esql-agg-sum]]
|
|
=== `SUM`
|
|
|
|
*Syntax*
|
|
|
|
[source,esql]
|
|
----
|
|
SUM(expression)
|
|
----
|
|
|
|
`expression`::
|
|
Numeric expression.
|
|
|
|
*Description*
|
|
|
|
Returns the sum of a numeric expression.
|
|
|
|
*Example*
|
|
|
|
[source.merge.styled,esql]
|
|
----
|
|
include::{esql-specs}/stats.csv-spec[tag=sum]
|
|
----
|
|
[%header.monospaced.styled,format=dsv,separator=|]
|
|
|===
|
|
include::{esql-specs}/stats.csv-spec[tag=sum-result]
|
|
|===
|
|
|
|
The expression can use inline functions. For example, to calculate
|
|
the sum of each employee's maximum salary changes, apply the
|
|
`MV_MAX` function to each row and then sum the results:
|
|
|
|
[source.merge.styled,esql]
|
|
----
|
|
include::{esql-specs}/stats.csv-spec[tag=docsStatsSumNestedExpression]
|
|
----
|
|
[%header.monospaced.styled,format=dsv,separator=|]
|
|
|===
|
|
include::{esql-specs}/stats.csv-spec[tag=docsStatsSumNestedExpression-result]
|
|
|===
|