aggs.asciidoc 23 KB

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