avg.asciidoc 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. [discrete]
  2. [[esql-agg-avg]]
  3. === `AVG`
  4. *Syntax*
  5. [source,esql]
  6. ----
  7. AVG(expression)
  8. ----
  9. `expression`::
  10. Numeric expression.
  11. //If `null`, the function returns `null`.
  12. // TODO: Remove comment when https://github.com/elastic/elasticsearch/issues/104900 is fixed.
  13. *Description*
  14. The average of a numeric expression.
  15. *Supported types*
  16. The result is always a `double` no matter the input type.
  17. *Examples*
  18. [source.merge.styled,esql]
  19. ----
  20. include::{esql-specs}/stats.csv-spec[tag=avg]
  21. ----
  22. [%header.monospaced.styled,format=dsv,separator=|]
  23. |===
  24. include::{esql-specs}/stats.csv-spec[tag=avg-result]
  25. |===
  26. The expression can use inline functions. For example, to calculate the average
  27. over a multivalued column, first use `MV_AVG` to average the multiple values per
  28. row, and use the result with the `AVG` function:
  29. [source.merge.styled,esql]
  30. ----
  31. include::{esql-specs}/stats.csv-spec[tag=docsStatsAvgNestedExpression]
  32. ----
  33. [%header.monospaced.styled,format=dsv,separator=|]
  34. |===
  35. include::{esql-specs}/stats.csv-spec[tag=docsStatsAvgNestedExpression-result]
  36. |===