|
| 1 | +[role="xpack"] |
| 2 | +[testenv="basic"] |
| 3 | +[[sql-functions-aggs]] |
| 4 | +=== Aggregate Functions |
| 5 | + |
| 6 | +Functions for computing a _single_ result from a set of input values. |
| 7 | +{es-sql} supports aggregate functions only alongside <<sql-syntax-group-by,grouping>> (implicit or explicit). |
| 8 | + |
| 9 | +==== General Purpose |
| 10 | + |
| 11 | +[[sql-functions-aggs-avg]] |
| 12 | +===== `AVG` |
| 13 | + |
| 14 | +*Input*: Numeric, *Output*: `double` |
| 15 | + |
| 16 | +https://en.wikipedia.org/wiki/Arithmetic_mean[Average] (arithmetic mean) of input values. |
| 17 | + |
| 18 | + |
| 19 | +["source","sql",subs="attributes,callouts,macros"] |
| 20 | +---- |
| 21 | +include-tagged::{sql-specs}/docs.csv-spec[aggAvg] |
| 22 | +---- |
| 23 | + |
| 24 | +[[sql-functions-aggs-count]] |
| 25 | +===== `COUNT` |
| 26 | + |
| 27 | +*Input*: Any, *Output*: `bigint` |
| 28 | + |
| 29 | +Total number (count) of input values. |
| 30 | + |
| 31 | +["source","sql",subs="attributes,callouts,macros"] |
| 32 | +---- |
| 33 | +include-tagged::{sql-specs}/docs.csv-spec[aggCountStar] |
| 34 | +---- |
| 35 | + |
| 36 | +[[sql-functions-aggs-count-distinct]] |
| 37 | +===== `COUNT(DISTINCT)` |
| 38 | + |
| 39 | +*Input*: Any, *Output*: `bigint` |
| 40 | + |
| 41 | +Total number of _distinct_ values in input values. |
| 42 | + |
| 43 | +["source","sql",subs="attributes,callouts,macros"] |
| 44 | +---- |
| 45 | +include-tagged::{sql-specs}/docs.csv-spec[aggCountDistinct] |
| 46 | +---- |
| 47 | + |
| 48 | +[[sql-functions-aggs-max]] |
| 49 | +===== `MAX` |
| 50 | + |
| 51 | +*Input*: Numeric, *Output*: Same as input |
| 52 | + |
| 53 | +Maximum value across input values. |
| 54 | + |
| 55 | +["source","sql",subs="attributes,callouts,macros"] |
| 56 | +---- |
| 57 | +include-tagged::{sql-specs}/docs.csv-spec[aggMax] |
| 58 | +---- |
| 59 | + |
| 60 | +[[sql-functions-aggs-min]] |
| 61 | +===== `MIN` |
| 62 | + |
| 63 | +*Input*: Numeric, *Output*: Same as input |
| 64 | + |
| 65 | +Minimum value across input values. |
| 66 | + |
| 67 | +["source","sql",subs="attributes,callouts,macros"] |
| 68 | +---- |
| 69 | +include-tagged::{sql-specs}/docs.csv-spec[aggMin] |
| 70 | +---- |
| 71 | + |
| 72 | +[[sql-functions-aggs-sum]] |
| 73 | +===== `SUM` |
| 74 | + |
| 75 | +*Input*: Numeric, *Output*: `bigint` for integer input, `double` for floating points |
| 76 | + |
| 77 | +Sum of input values. |
| 78 | + |
| 79 | +["source","sql",subs="attributes,callouts,macros"] |
| 80 | +---- |
| 81 | +include-tagged::{sql-specs}/docs.csv-spec[aggSum] |
| 82 | +---- |
| 83 | + |
| 84 | +==== Statistics |
| 85 | + |
| 86 | +[[sql-functions-aggs-kurtosis]] |
| 87 | +===== `KURTOSIS` |
| 88 | + |
| 89 | +*Input*: Numeric, *Output*: `double` |
| 90 | + |
| 91 | +https://en.wikipedia.org/wiki/Kurtosis[Quantify] the shape of the distribution of input values. |
| 92 | + |
| 93 | +["source","sql",subs="attributes,callouts,macros"] |
| 94 | +---- |
| 95 | +include-tagged::{sql-specs}/docs.csv-spec[aggKurtosis] |
| 96 | +---- |
| 97 | + |
| 98 | +[[sql-functions-aggs-percentile]] |
| 99 | +===== `PERCENTILE` |
| 100 | + |
| 101 | +*Input*: Numeric, *Output*: `double` |
| 102 | + |
| 103 | +The nth https://en.wikipedia.org/wiki/Percentile[percentile] of input values. |
| 104 | + |
| 105 | +["source","sql",subs="attributes,callouts,macros"] |
| 106 | +---- |
| 107 | +include-tagged::{sql-specs}/docs.csv-spec[aggPercentile] |
| 108 | +---- |
| 109 | + |
| 110 | +[[sql-functions-aggs-percentile-rank]] |
| 111 | +===== `PERCENTILE_RANK` |
| 112 | + |
| 113 | +*Input*: Numeric, *Output*: `double` |
| 114 | + |
| 115 | +The https://en.wikipedia.org/wiki/Percentile_rank[percentile rank] of input values of input values. |
| 116 | + |
| 117 | +["source","sql",subs="attributes,callouts,macros"] |
| 118 | +---- |
| 119 | +include-tagged::{sql-specs}/docs.csv-spec[aggPercentileRank] |
| 120 | +---- |
| 121 | + |
| 122 | +[[sql-functions-aggs-skewness]] |
| 123 | +===== `SKEWNESS` |
| 124 | + |
| 125 | +*Input*: Numeric, *Output*: `double` |
| 126 | + |
| 127 | +https://en.wikipedia.org/wiki/Skewness[Quantify] the asymmetric distribution of input values. |
| 128 | + |
| 129 | +["source","sql",subs="attributes,callouts,macros"] |
| 130 | +---- |
| 131 | +include-tagged::{sql-specs}/docs.csv-spec[aggSkewness] |
| 132 | +---- |
| 133 | + |
| 134 | +[[sql-functions-aggs-stddev-pop]] |
| 135 | +===== `STDDEV_POP` |
| 136 | + |
| 137 | +*Input*: Numeric, *Output*: `double` |
| 138 | + |
| 139 | +https://en.wikipedia.org/wiki/Standard_deviations[Population standard deviation] of input values. |
| 140 | + |
| 141 | +["source","sql",subs="attributes,callouts,macros"] |
| 142 | +---- |
| 143 | +include-tagged::{sql-specs}/docs.csv-spec[aggStddevPop] |
| 144 | +---- |
| 145 | + |
| 146 | +[[sql-functions-aggs-sum-squares]] |
| 147 | +===== `SUM_OF_SQUARES` |
| 148 | + |
| 149 | +*Input*: Numeric, *Output*: `double` |
| 150 | + |
| 151 | +https://en.wikipedia.org/wiki/Total_sum_of_squares[Sum of squares] of input values. |
| 152 | + |
| 153 | +["source","sql",subs="attributes,callouts,macros"] |
| 154 | +---- |
| 155 | +include-tagged::{sql-specs}/docs.csv-spec[aggSumOfSquares] |
| 156 | +---- |
| 157 | + |
| 158 | +[[sql-functions-aggs-var-pop]] |
| 159 | +===== `VAR_POP` |
| 160 | + |
| 161 | +*Input*: Numeric, *Output*: `double` |
| 162 | + |
| 163 | +https://en.wikipedia.org/wiki/Variance[Population] variance of input values. |
| 164 | + |
| 165 | +["source","sql",subs="attributes,callouts,macros"] |
| 166 | +---- |
| 167 | +include-tagged::{sql-specs}/docs.csv-spec[aggVarPop] |
| 168 | +---- |
0 commit comments