aggs.asciidoc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  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. [[sql-functions-aggs-general]]
  8. [discrete]
  9. === General Purpose
  10. [[sql-functions-aggs-avg]]
  11. ==== `AVG`
  12. .Synopsis:
  13. [source, sql]
  14. --------------------------------------------------
  15. AVG(numeric_field) <1>
  16. --------------------------------------------------
  17. *Input*:
  18. <1> numeric field. If this field contains only `null` values, the function
  19. returns `null`. Otherwise, the function ignores `null` values in this field.
  20. *Output*: `double` numeric value
  21. *Description*: Returns the {wikipedia}/Arithmetic_mean[Average] (arithmetic mean) of input values.
  22. ["source","sql",subs="attributes,macros"]
  23. --------------------------------------------------
  24. include-tagged::{sql-specs}/docs/docs.csv-spec[aggAvg]
  25. --------------------------------------------------
  26. ["source","sql",subs="attributes,macros"]
  27. --------------------------------------------------
  28. include-tagged::{sql-specs}/docs/docs.csv-spec[aggAvgScalars]
  29. --------------------------------------------------
  30. [[sql-functions-aggs-count]]
  31. ==== `COUNT`
  32. .Synopsis:
  33. [source, sql]
  34. --------------------------------------------------
  35. COUNT(expression) <1>
  36. --------------------------------------------------
  37. *Input*:
  38. <1> a field name, wildcard (`*`) or any numeric value. For `COUNT(*)` or
  39. `COUNT(<literal>)`, all values are considered, including `null` or missing
  40. ones. For `COUNT(<field_name>)`, `null` values are not considered.
  41. *Output*: numeric value
  42. *Description*: Returns the total number (count) of input values.
  43. ["source","sql",subs="attributes,macros"]
  44. --------------------------------------------------
  45. include-tagged::{sql-specs}/docs/docs.csv-spec[aggCountStar]
  46. --------------------------------------------------
  47. [[sql-functions-aggs-count-all]]
  48. ==== `COUNT(ALL)`
  49. .Synopsis:
  50. [source, sql]
  51. --------------------------------------------------
  52. COUNT(ALL field_name) <1>
  53. --------------------------------------------------
  54. *Input*:
  55. <1> a field name. If this field contains only `null` values, the function
  56. returns `null`. Otherwise, the function ignores `null` values in this field.
  57. *Output*: numeric value
  58. *Description*: Returns the total number (count) of all _non-null_ input values. `COUNT(<field_name>)` and `COUNT(ALL <field_name>)` are equivalent.
  59. ["source","sql",subs="attributes,macros"]
  60. --------------------------------------------------
  61. include-tagged::{sql-specs}/docs/docs.csv-spec[aggCountAll]
  62. --------------------------------------------------
  63. ["source","sql",subs="attributes,macros"]
  64. --------------------------------------------------
  65. include-tagged::{sql-specs}/docs/docs.csv-spec[aggCountAllScalars]
  66. --------------------------------------------------
  67. [[sql-functions-aggs-count-distinct]]
  68. ==== `COUNT(DISTINCT)`
  69. .Synopsis:
  70. [source, sql]
  71. --------------------------------------------------
  72. COUNT(DISTINCT field_name) <1>
  73. --------------------------------------------------
  74. *Input*:
  75. <1> a field name
  76. *Output*: numeric value. If this field contains only `null` values, the function
  77. returns `null`. Otherwise, the function ignores `null` values in this field.
  78. *Description*: Returns the total number of _distinct non-null_ values in input values.
  79. ["source","sql",subs="attributes,macros"]
  80. --------------------------------------------------
  81. include-tagged::{sql-specs}/docs/docs.csv-spec[aggCountDistinct]
  82. --------------------------------------------------
  83. ["source","sql",subs="attributes,macros"]
  84. --------------------------------------------------
  85. include-tagged::{sql-specs}/docs/docs.csv-spec[aggCountDistinctScalars]
  86. --------------------------------------------------
  87. [[sql-functions-aggs-first]]
  88. ==== `FIRST/FIRST_VALUE`
  89. .Synopsis:
  90. [source, sql]
  91. ----------------------------------------------
  92. FIRST(
  93. field_name <1>
  94. [, ordering_field_name]) <2>
  95. ----------------------------------------------
  96. *Input*:
  97. <1> target field for the aggregation
  98. <2> optional field used for ordering
  99. *Output*: same type as the input
  100. *Description*: Returns the first non-`null` value (if such exists) of the `field_name` input column sorted by
  101. the `ordering_field_name` column. If `ordering_field_name` is not provided, only the `field_name`
  102. column is used for the sorting. E.g.:
  103. [cols="<,<"]
  104. |===
  105. s| a | b
  106. | 100 | 1
  107. | 200 | 1
  108. | 1 | 2
  109. | 2 | 2
  110. | 10 | null
  111. | 20 | null
  112. | null | null
  113. |===
  114. [source, sql]
  115. ----------------------
  116. SELECT FIRST(a) FROM t
  117. ----------------------
  118. will result in:
  119. [cols="<"]
  120. |===
  121. s| FIRST(a)
  122. | 1
  123. |===
  124. and
  125. [source, sql]
  126. -------------------------
  127. SELECT FIRST(a, b) FROM t
  128. -------------------------
  129. will result in:
  130. [cols="<"]
  131. |===
  132. s| FIRST(a, b)
  133. | 100
  134. |===
  135. ["source","sql",subs="attributes,macros"]
  136. -----------------------------------------------------------
  137. include-tagged::{sql-specs}/docs/docs.csv-spec[firstWithOneArg]
  138. -----------------------------------------------------------
  139. ["source","sql",subs="attributes,macros"]
  140. --------------------------------------------------------------------
  141. include-tagged::{sql-specs}/docs/docs.csv-spec[firstWithOneArgAndGroupBy]
  142. --------------------------------------------------------------------
  143. ["source","sql",subs="attributes,macros"]
  144. -----------------------------------------------------------
  145. include-tagged::{sql-specs}/docs/docs.csv-spec[firstWithTwoArgs]
  146. -----------------------------------------------------------
  147. ["source","sql",subs="attributes,macros"]
  148. ---------------------------------------------------------------------
  149. include-tagged::{sql-specs}/docs/docs.csv-spec[firstWithTwoArgsAndGroupBy]
  150. ---------------------------------------------------------------------
  151. `FIRST_VALUE` is a name alias and can be used instead of `FIRST`, e.g.:
  152. ["source","sql",subs="attributes,macros"]
  153. --------------------------------------------------------------------------
  154. include-tagged::{sql-specs}/docs/docs.csv-spec[firstValueWithTwoArgsAndGroupBy]
  155. --------------------------------------------------------------------------
  156. ["source","sql",subs="attributes,macros"]
  157. --------------------------------------------------------------------------
  158. include-tagged::{sql-specs}/docs/docs.csv-spec[firstValueWithTwoArgsAndGroupByScalars]
  159. --------------------------------------------------------------------------
  160. [NOTE]
  161. `FIRST` cannot be used in a HAVING clause.
  162. [NOTE]
  163. `FIRST` cannot be used with columns of type <<text, `text`>> unless
  164. the field is also <<before-enabling-fielddata,saved as a keyword>>.
  165. [[sql-functions-aggs-last]]
  166. ==== `LAST/LAST_VALUE`
  167. .Synopsis:
  168. [source, sql]
  169. --------------------------------------------------
  170. LAST(
  171. field_name <1>
  172. [, ordering_field_name]) <2>
  173. --------------------------------------------------
  174. *Input*:
  175. <1> target field for the aggregation
  176. <2> optional field used for ordering
  177. *Output*: same type as the input
  178. *Description*: It's the inverse of <<sql-functions-aggs-first>>. Returns the last non-`null` value (if such exists) of the
  179. `field_name` input column sorted descending by the `ordering_field_name` column. If `ordering_field_name` is not
  180. provided, only the `field_name` column is used for the sorting. E.g.:
  181. [cols="<,<"]
  182. |===
  183. s| a | b
  184. | 10 | 1
  185. | 20 | 1
  186. | 1 | 2
  187. | 2 | 2
  188. | 100 | null
  189. | 200 | null
  190. | null | null
  191. |===
  192. [source, sql]
  193. ------------------------
  194. SELECT LAST(a) FROM t
  195. ------------------------
  196. will result in:
  197. [cols="<"]
  198. |===
  199. s| LAST(a)
  200. | 200
  201. |===
  202. and
  203. [source, sql]
  204. ------------------------
  205. SELECT LAST(a, b) FROM t
  206. ------------------------
  207. will result in:
  208. [cols="<"]
  209. |===
  210. s| LAST(a, b)
  211. | 2
  212. |===
  213. ["source","sql",subs="attributes,macros"]
  214. -----------------------------------------------------------
  215. include-tagged::{sql-specs}/docs/docs.csv-spec[lastWithOneArg]
  216. -----------------------------------------------------------
  217. ["source","sql",subs="attributes,macros"]
  218. -------------------------------------------------------------------
  219. include-tagged::{sql-specs}/docs/docs.csv-spec[lastWithOneArgAndGroupBy]
  220. -------------------------------------------------------------------
  221. ["source","sql",subs="attributes,macros"]
  222. -----------------------------------------------------------
  223. include-tagged::{sql-specs}/docs/docs.csv-spec[lastWithTwoArgs]
  224. -----------------------------------------------------------
  225. ["source","sql",subs="attributes,macros"]
  226. --------------------------------------------------------------------
  227. include-tagged::{sql-specs}/docs/docs.csv-spec[lastWithTwoArgsAndGroupBy]
  228. --------------------------------------------------------------------
  229. `LAST_VALUE` is a name alias and can be used instead of `LAST`, e.g.:
  230. ["source","sql",subs="attributes,macros"]
  231. -------------------------------------------------------------------------
  232. include-tagged::{sql-specs}/docs/docs.csv-spec[lastValueWithTwoArgsAndGroupBy]
  233. -------------------------------------------------------------------------
  234. ["source","sql",subs="attributes,macros"]
  235. -------------------------------------------------------------------------
  236. include-tagged::{sql-specs}/docs/docs.csv-spec[lastValueWithTwoArgsAndGroupByScalars]
  237. -------------------------------------------------------------------------
  238. [NOTE]
  239. `LAST` cannot be used in `HAVING` clause.
  240. [NOTE]
  241. `LAST` cannot be used with columns of type <<text, `text`>> unless
  242. the field is also <<before-enabling-fielddata,`saved as a keyword`>>.
  243. [[sql-functions-aggs-max]]
  244. ==== `MAX`
  245. .Synopsis:
  246. [source, sql]
  247. --------------------------------------------------
  248. MAX(field_name) <1>
  249. --------------------------------------------------
  250. *Input*:
  251. <1> a numeric field. If this field contains only `null` values, the function
  252. returns `null`. Otherwise, the function ignores `null` values in this field.
  253. *Output*: same type as the input
  254. *Description*: Returns the maximum value across input values in the field `field_name`.
  255. ["source","sql",subs="attributes,macros"]
  256. --------------------------------------------------
  257. include-tagged::{sql-specs}/docs/docs.csv-spec[aggMax]
  258. --------------------------------------------------
  259. ["source","sql",subs="attributes,macros"]
  260. --------------------------------------------------
  261. include-tagged::{sql-specs}/docs/docs.csv-spec[aggMaxScalars]
  262. --------------------------------------------------
  263. [NOTE]
  264. `MAX` on a field of type <<text, `text`>> or <<keyword, `keyword`>> is translated into
  265. <<sql-functions-aggs-last>> and therefore, it cannot be used in `HAVING` clause.
  266. [[sql-functions-aggs-min]]
  267. ==== `MIN`
  268. .Synopsis:
  269. [source, sql]
  270. --------------------------------------------------
  271. MIN(field_name) <1>
  272. --------------------------------------------------
  273. *Input*:
  274. <1> a numeric field. If this field contains only `null` values, the function
  275. returns `null`. Otherwise, the function ignores `null` values in this field.
  276. *Output*: same type as the input
  277. *Description*: Returns the minimum value across input values in the field `field_name`.
  278. ["source","sql",subs="attributes,macros"]
  279. --------------------------------------------------
  280. include-tagged::{sql-specs}/docs/docs.csv-spec[aggMin]
  281. --------------------------------------------------
  282. [NOTE]
  283. `MIN` on a field of type <<text, `text`>> or <<keyword, `keyword`>> is translated into
  284. <<sql-functions-aggs-first>> and therefore, it cannot be used in `HAVING` clause.
  285. [[sql-functions-aggs-sum]]
  286. ==== `SUM`
  287. .Synopsis:
  288. [source, sql]
  289. --------------------------------------------------
  290. SUM(field_name) <1>
  291. --------------------------------------------------
  292. *Input*:
  293. <1> a numeric field. If this field contains only `null` values, the function
  294. returns `null`. Otherwise, the function ignores `null` values in this field.
  295. *Output*: `bigint` for integer input, `double` for floating points
  296. *Description*: Returns the sum of input values in the field `field_name`.
  297. ["source","sql",subs="attributes,macros"]
  298. --------------------------------------------------
  299. include-tagged::{sql-specs}/docs/docs.csv-spec[aggSum]
  300. --------------------------------------------------
  301. ["source","sql",subs="attributes,macros"]
  302. --------------------------------------------------
  303. include-tagged::{sql-specs}/docs/docs.csv-spec[aggSumScalars]
  304. --------------------------------------------------
  305. [[sql-functions-aggs-statistics]]
  306. [discrete]
  307. === Statistics
  308. [[sql-functions-aggs-kurtosis]]
  309. ==== `KURTOSIS`
  310. .Synopsis:
  311. [source, sql]
  312. --------------------------------------------------
  313. KURTOSIS(field_name) <1>
  314. --------------------------------------------------
  315. *Input*:
  316. <1> a numeric field. If this field contains only `null` values, the function
  317. returns `null`. Otherwise, the function ignores `null` values in this field.
  318. *Output*: `double` numeric value
  319. *Description*:
  320. {wikipedia}/Kurtosis[Quantify] the shape of the distribution of input values in the field `field_name`.
  321. ["source","sql",subs="attributes,macros"]
  322. --------------------------------------------------
  323. include-tagged::{sql-specs}/docs/docs.csv-spec[aggKurtosis]
  324. --------------------------------------------------
  325. [NOTE]
  326. ====
  327. `KURTOSIS` cannot be used on top of scalar functions or operators but only directly on a field. So, for example,
  328. the following is not allowed and an error is returned:
  329. [source, sql]
  330. ---------------------------------------
  331. SELECT KURTOSIS(salary / 12.0), gender FROM emp GROUP BY gender
  332. ---------------------------------------
  333. ====
  334. [[sql-functions-aggs-mad]]
  335. ==== `MAD`
  336. .Synopsis:
  337. [source, sql]
  338. --------------------------------------------------
  339. MAD(field_name) <1>
  340. --------------------------------------------------
  341. *Input*:
  342. <1> a numeric field. If this field contains only `null` values, the function
  343. returns `null`. Otherwise, the function ignores `null` values in this field.
  344. *Output*: `double` numeric value
  345. *Description*:
  346. {wikipedia}/Median_absolute_deviation[Measure] the variability of the input values in the field `field_name`.
  347. ["source","sql",subs="attributes,macros"]
  348. --------------------------------------------------
  349. include-tagged::{sql-specs}/docs/docs.csv-spec[aggMad]
  350. --------------------------------------------------
  351. ["source","sql",subs="attributes,macros"]
  352. --------------------------------------------------
  353. include-tagged::{sql-specs}/docs/docs.csv-spec[aggMadScalars]
  354. --------------------------------------------------
  355. [[sql-functions-aggs-percentile]]
  356. ==== `PERCENTILE`
  357. .Synopsis:
  358. [source, sql]
  359. --------------------------------------------------
  360. PERCENTILE(
  361. field_name, <1>
  362. percentile[, <2>
  363. method[, <3>
  364. method_parameter]]) <4>
  365. --------------------------------------------------
  366. *Input*:
  367. <1> a numeric field. If this field contains only `null` values, the function
  368. returns `null`. Otherwise, the function ignores `null` values in this field.
  369. <2> a numeric expression (must be a constant and not based on a field). If
  370. `null`, the function returns `null`.
  371. <3> optional string literal for the <<search-aggregations-metrics-percentile-aggregation-approximation,percentile algorithm>>. Possible values: `tdigest` or `hdr`. Defaults to `tdigest`.
  372. <4> optional numeric literal that configures the <<search-aggregations-metrics-percentile-aggregation-approximation,percentile algorithm>>. Configures `compression` for `tdigest` or `number_of_significant_value_digits` for `hdr`. The default is the same as that of the backing algorithm.
  373. *Output*: `double` numeric value
  374. *Description*:
  375. Returns the nth {wikipedia}/Percentile[percentile] (represented by `numeric_exp` parameter)
  376. of input values in the field `field_name`.
  377. ["source","sql",subs="attributes,macros"]
  378. --------------------------------------------------
  379. include-tagged::{sql-specs}/docs/docs.csv-spec[aggPercentile]
  380. --------------------------------------------------
  381. ["source","sql",subs="attributes,macros"]
  382. --------------------------------------------------
  383. include-tagged::{sql-specs}/docs/docs.csv-spec[aggPercentileScalars]
  384. --------------------------------------------------
  385. ["source","sql",subs="attributes,macros"]
  386. --------------------------------------------------
  387. include-tagged::{sql-specs}/docs/docs.csv-spec[aggPercentileWithPercentileConfig]
  388. --------------------------------------------------
  389. [[sql-functions-aggs-percentile-rank]]
  390. ==== `PERCENTILE_RANK`
  391. .Synopsis:
  392. [source, sql]
  393. --------------------------------------------------
  394. PERCENTILE_RANK(
  395. field_name, <1>
  396. value[, <2>
  397. method[, <3>
  398. method_parameter]]) <4>
  399. --------------------------------------------------
  400. *Input*:
  401. <1> a numeric field. If this field contains only `null` values, the function
  402. returns `null`. Otherwise, the function ignores `null` values in this field.
  403. <2> a numeric expression (must be a constant and not based on a field). If
  404. `null`, the function returns `null`.
  405. <3> optional string literal for the <<search-aggregations-metrics-percentile-aggregation-approximation,percentile algorithm>>. Possible values: `tdigest` or `hdr`. Defaults to `tdigest`.
  406. <4> optional numeric literal that configures the <<search-aggregations-metrics-percentile-aggregation-approximation,percentile algorithm>>. Configures `compression` for `tdigest` or `number_of_significant_value_digits` for `hdr`. The default is the same as that of the backing algorithm.
  407. *Output*: `double` numeric value
  408. *Description*:
  409. Returns the nth {wikipedia}/Percentile_rank[percentile rank] (represented by `numeric_exp` parameter)
  410. of input values in the field `field_name`.
  411. ["source","sql",subs="attributes,macros"]
  412. --------------------------------------------------
  413. include-tagged::{sql-specs}/docs/docs.csv-spec[aggPercentileRank]
  414. --------------------------------------------------
  415. ["source","sql",subs="attributes,macros"]
  416. --------------------------------------------------
  417. include-tagged::{sql-specs}/docs/docs.csv-spec[aggPercentileRankScalars]
  418. --------------------------------------------------
  419. ["source","sql",subs="attributes,macros"]
  420. --------------------------------------------------
  421. include-tagged::{sql-specs}/docs/docs.csv-spec[aggPercentileRankWithPercentileConfig]
  422. --------------------------------------------------
  423. [[sql-functions-aggs-skewness]]
  424. ==== `SKEWNESS`
  425. .Synopsis:
  426. [source, sql]
  427. --------------------------------------------------
  428. SKEWNESS(field_name) <1>
  429. --------------------------------------------------
  430. *Input*:
  431. <1> a numeric field. If this field contains only `null` values, the function
  432. returns `null`. Otherwise, the function ignores `null` values in this field.
  433. *Output*: `double` numeric value
  434. *Description*:
  435. {wikipedia}/Skewness[Quantify] the asymmetric distribution of input values in the field `field_name`.
  436. ["source","sql",subs="attributes,macros"]
  437. --------------------------------------------------
  438. include-tagged::{sql-specs}/docs/docs.csv-spec[aggSkewness]
  439. --------------------------------------------------
  440. [NOTE]
  441. ====
  442. `SKEWNESS` cannot be used on top of scalar functions but only directly on a field. So, for example, the following is
  443. not allowed and an error is returned:
  444. [source, sql]
  445. ---------------------------------------
  446. SELECT SKEWNESS(ROUND(salary / 12.0, 2), gender FROM emp GROUP BY gender
  447. ---------------------------------------
  448. ====
  449. [[sql-functions-aggs-stddev-pop]]
  450. ==== `STDDEV_POP`
  451. .Synopsis:
  452. [source, sql]
  453. --------------------------------------------------
  454. STDDEV_POP(field_name) <1>
  455. --------------------------------------------------
  456. *Input*:
  457. <1> a numeric field. If this field contains only `null` values, the function
  458. returns `null`. Otherwise, the function ignores `null` values in this field.
  459. *Output*: `double` numeric value
  460. *Description*:
  461. Returns the {wikipedia}/Standard_deviations[population standard deviation] of input values in the field `field_name`.
  462. ["source","sql",subs="attributes,macros"]
  463. --------------------------------------------------
  464. include-tagged::{sql-specs}/docs/docs.csv-spec[aggStddevPop]
  465. --------------------------------------------------
  466. ["source","sql",subs="attributes,macros"]
  467. --------------------------------------------------
  468. include-tagged::{sql-specs}/docs/docs.csv-spec[aggStddevPopScalars]
  469. --------------------------------------------------
  470. [[sql-functions-aggs-stddev-samp]]
  471. ==== `STDDEV_SAMP`
  472. .Synopsis:
  473. [source, sql]
  474. --------------------------------------------------
  475. STDDEV_SAMP(field_name) <1>
  476. --------------------------------------------------
  477. *Input*:
  478. <1> a numeric field. If this field contains only `null` values, the function
  479. returns `null`. Otherwise, the function ignores `null` values in this field.
  480. *Output*: `double` numeric value
  481. *Description*:
  482. Returns the {wikipedia}/Standard_deviations[sample standard deviation] of input values in the field `field_name`.
  483. ["source","sql",subs="attributes,macros"]
  484. --------------------------------------------------
  485. include-tagged::{sql-specs}/docs/docs.csv-spec[aggStddevSamp]
  486. --------------------------------------------------
  487. ["source","sql",subs="attributes,macros"]
  488. --------------------------------------------------
  489. include-tagged::{sql-specs}/docs/docs.csv-spec[aggStddevSampScalars]
  490. --------------------------------------------------
  491. [[sql-functions-aggs-sum-squares]]
  492. ==== `SUM_OF_SQUARES`
  493. .Synopsis:
  494. [source, sql]
  495. --------------------------------------------------
  496. SUM_OF_SQUARES(field_name) <1>
  497. --------------------------------------------------
  498. *Input*:
  499. <1> a numeric field. If this field contains only `null` values, the function
  500. returns `null`. Otherwise, the function ignores `null` values in this field.
  501. *Output*: `double` numeric value
  502. *Description*:
  503. Returns the sum of squares of input values in the field `field_name`.
  504. ["source","sql",subs="attributes,macros"]
  505. --------------------------------------------------
  506. include-tagged::{sql-specs}/docs/docs.csv-spec[aggSumOfSquares]
  507. --------------------------------------------------
  508. ["source","sql",subs="attributes,macros"]
  509. --------------------------------------------------
  510. include-tagged::{sql-specs}/docs/docs.csv-spec[aggSumOfSquaresScalars]
  511. --------------------------------------------------
  512. [[sql-functions-aggs-var-pop]]
  513. ==== `VAR_POP`
  514. .Synopsis:
  515. [source, sql]
  516. --------------------------------------------------
  517. VAR_POP(field_name) <1>
  518. --------------------------------------------------
  519. *Input*:
  520. <1> a numeric field. If this field contains only `null` values, the function
  521. returns `null`. Otherwise, the function ignores `null` values in this field.
  522. *Output*: `double` numeric value
  523. *Description*:
  524. Returns the {wikipedia}/Variance[population variance] of input values in the field `field_name`.
  525. ["source","sql",subs="attributes,macros"]
  526. --------------------------------------------------
  527. include-tagged::{sql-specs}/docs/docs.csv-spec[aggVarPop]
  528. --------------------------------------------------
  529. ["source","sql",subs="attributes,macros"]
  530. --------------------------------------------------
  531. include-tagged::{sql-specs}/docs/docs.csv-spec[aggVarPopScalars]
  532. --------------------------------------------------
  533. [[sql-functions-aggs-var-samp]]
  534. ==== `VAR_SAMP`
  535. .Synopsis:
  536. [source, sql]
  537. --------------------------------------------------
  538. VAR_SAMP(field_name) <1>
  539. --------------------------------------------------
  540. *Input*:
  541. <1> a numeric field. If this field contains only `null` values, the function
  542. returns `null`. Otherwise, the function ignores `null` values in this field.
  543. *Output*: `double` numeric value
  544. *Description*:
  545. Returns the {wikipedia}/Variance[sample variance] of input values in the field `field_name`.
  546. ["source","sql",subs="attributes,macros"]
  547. --------------------------------------------------
  548. include-tagged::{sql-specs}/docs/docs.csv-spec[aggVarSamp]
  549. --------------------------------------------------
  550. ["source","sql",subs="attributes,macros"]
  551. --------------------------------------------------
  552. include-tagged::{sql-specs}/docs/docs.csv-spec[aggVarSampScalars]
  553. --------------------------------------------------