aggs.asciidoc 21 KB

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