aggs.asciidoc 3.8 KB

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