elasticsearch/docs/reference/esql/functions/avg.asciidoc

48 lines
1.0 KiB
Plaintext

[discrete]
[[esql-agg-avg]]
=== `AVG`
*Syntax*
[source,esql]
----
AVG(expression)
----
`expression`::
Numeric expression.
//If `null`, the function returns `null`.
// TODO: Remove comment when https://github.com/elastic/elasticsearch/issues/104900 is fixed.
*Description*
The average of a numeric expression.
*Supported types*
The result is always a `double` no matter the input type.
*Examples*
[source.merge.styled,esql]
----
include::{esql-specs}/stats.csv-spec[tag=avg]
----
[%header.monospaced.styled,format=dsv,separator=|]
|===
include::{esql-specs}/stats.csv-spec[tag=avg-result]
|===
The expression can use inline functions. For example, to calculate the average
over a multivalued column, first use `MV_AVG` to average the multiple values per
row, and use the result with the `AVG` function:
[source.merge.styled,esql]
----
include::{esql-specs}/stats.csv-spec[tag=docsStatsAvgNestedExpression]
----
[%header.monospaced.styled,format=dsv,separator=|]
|===
include::{esql-specs}/stats.csv-spec[tag=docsStatsAvgNestedExpression-result]
|===