aggs.asciidoc 3.8 KB

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