123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- [role="xpack"]
- [testenv="basic"]
- [[sql-functions-aggs]]
- === Aggregate Functions
- beta[]
- Functions for computing a _single_ result from a set of input values.
- {es-sql} supports aggregate functions only alongside <<sql-syntax-group-by,grouping>> (implicit or explicit).
- ==== General Purpose
- [[sql-functions-aggs-avg]]
- ===== `AVG`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- AVG(numeric_field<1>)
- --------------------------------------------------
- *Input*:
- <1> numeric field
- *Output*: `double` numeric value
- .Description:
- Returns the https://en.wikipedia.org/wiki/Arithmetic_mean[Average] (arithmetic mean) of input values.
- ["source","sql",subs="attributes,macros"]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs.csv-spec[aggAvg]
- --------------------------------------------------
- [[sql-functions-aggs-count]]
- ===== `COUNT`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- COUNT(expression<1>)
- --------------------------------------------------
- *Input*:
- <1> a field name, wildcard (`*`) or any numeric value
- *Output*: numeric value
- .Description:
- Returns the total number (count) of input values.
- ["source","sql",subs="attributes,macros"]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs.csv-spec[aggCountStar]
- --------------------------------------------------
- [[sql-functions-aggs-count-distinct]]
- ===== `COUNT(DISTINCT)`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- COUNT(DISTINCT field_name<1>)
- --------------------------------------------------
- *Input*:
- <1> a field name
- *Output*: numeric value
- .Description:
- Returns the total number of _distinct_ values in input values.
- ["source","sql",subs="attributes,macros"]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs.csv-spec[aggCountDistinct]
- --------------------------------------------------
- [[sql-functions-aggs-max]]
- ===== `MAX`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- MAX(field_name<1>)
- --------------------------------------------------
- *Input*:
- <1> a numeric field
- *Output*: same type as the input
- .Description:
- Returns the maximum value across input values in the field `field_name`.
- ["source","sql",subs="attributes,macros"]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs.csv-spec[aggMax]
- --------------------------------------------------
- [[sql-functions-aggs-min]]
- ===== `MIN`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- MIN(field_name<1>)
- --------------------------------------------------
- *Input*:
- <1> a numeric field
- *Output*: same type as the input
- .Description:
- Returns the minimum value across input values in the field `field_name`.
- ["source","sql",subs="attributes,macros"]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs.csv-spec[aggMin]
- --------------------------------------------------
- [[sql-functions-aggs-sum]]
- ===== `SUM`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- SUM(field_name<1>)
- --------------------------------------------------
- *Input*:
- <1> a numeric field
- *Output*: `bigint` for integer input, `double` for floating points
- .Description:
- Returns the sum of input values in the field `field_name`.
- ["source","sql",subs="attributes,macros"]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs.csv-spec[aggSum]
- --------------------------------------------------
- ==== Statistics
- [[sql-functions-aggs-kurtosis]]
- ===== `KURTOSIS`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- KURTOSIS(field_name<1>)
- --------------------------------------------------
- *Input*:
- <1> a numeric field
- *Output*: `double` numeric value
- .Description:
- https://en.wikipedia.org/wiki/Kurtosis[Quantify] the shape of the distribution of input values in the field `field_name`.
- ["source","sql",subs="attributes,macros"]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs.csv-spec[aggKurtosis]
- --------------------------------------------------
- [[sql-functions-aggs-percentile]]
- ===== `PERCENTILE`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- PERCENTILE(field_name<1>, numeric_exp<2>)
- --------------------------------------------------
- *Input*:
- <1> a numeric field
- <2> a numeric expression
- *Output*: `double` numeric value
- .Description:
- Returns the nth https://en.wikipedia.org/wiki/Percentile[percentile] (represented by `numeric_exp` parameter)
- of input values in the field `field_name`.
- ["source","sql",subs="attributes,macros"]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs.csv-spec[aggPercentile]
- --------------------------------------------------
- [[sql-functions-aggs-percentile-rank]]
- ===== `PERCENTILE_RANK`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- PERCENTILE_RANK(field_name<1>, numeric_exp<2>)
- --------------------------------------------------
- *Input*:
- <1> a numeric field
- <2> a numeric expression
- *Output*: `double` numeric value
- .Description:
- Returns the nth https://en.wikipedia.org/wiki/Percentile_rank[percentile rank] (represented by `numeric_exp` parameter)
- of input values in the field `field_name`.
- ["source","sql",subs="attributes,macros"]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs.csv-spec[aggPercentileRank]
- --------------------------------------------------
- [[sql-functions-aggs-skewness]]
- ===== `SKEWNESS`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- SKEWNESS(field_name<1>)
- --------------------------------------------------
- *Input*:
- <1> a numeric field
- *Output*: `double` numeric value
- .Description:
- https://en.wikipedia.org/wiki/Skewness[Quantify] the asymmetric distribution of input values in the field `field_name`.
- ["source","sql",subs="attributes,macros"]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs.csv-spec[aggSkewness]
- --------------------------------------------------
- [[sql-functions-aggs-stddev-pop]]
- ===== `STDDEV_POP`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- STDDEV_POP(field_name<1>)
- --------------------------------------------------
- *Input*:
- <1> a numeric field
- *Output*: `double` numeric value
- .Description:
- Returns the https://en.wikipedia.org/wiki/Standard_deviations[population standard deviation] of input values in the field `field_name`.
- ["source","sql",subs="attributes,macros"]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs.csv-spec[aggStddevPop]
- --------------------------------------------------
- [[sql-functions-aggs-sum-squares]]
- ===== `SUM_OF_SQUARES`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- SUM_OF_SQUARES(field_name<1>)
- --------------------------------------------------
- *Input*:
- <1> a numeric field
- *Output*: `double` numeric value
- .Description:
- Returns the https://en.wikipedia.org/wiki/Total_sum_of_squares[sum of squares] of input values in the field `field_name`.
- ["source","sql",subs="attributes,macros"]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs.csv-spec[aggSumOfSquares]
- --------------------------------------------------
- [[sql-functions-aggs-var-pop]]
- ===== `VAR_POP`
- .Synopsis:
- [source, sql]
- --------------------------------------------------
- VAR_POP(field_name<1>)
- --------------------------------------------------
- *Input*:
- <1> a numeric field
- *Output*: `double` numeric value
- .Description:
- Returns the https://en.wikipedia.org/wiki/Variance[population variance] of input values in the field `field_name`.
- ["source","sql",subs="attributes,macros"]
- --------------------------------------------------
- include-tagged::{sql-specs}/docs.csv-spec[aggVarPop]
- --------------------------------------------------
|