

For similar capabilities to Amazon Timestream for LiveAnalytics, consider Amazon Timestream for InfluxDB. It offers simplified data ingestion and single-digit millisecond query response times for real-time analytics. Learn more [here](https://docs.aws.amazon.com//timestream/latest/developerguide/timestream-for-influxdb.html).

# Aggregate functions
<a name="aggregate-functions"></a>

Timestream for LiveAnalytics supports the following aggregate functions.


| Function | Output data type | Description | 
| --- | --- | --- | 
|  arbitrary(x)  |  [same as input]  |  Returns an arbitrary non-null value of x, if one exists. <pre>SELECT arbitrary(t.c) FROM (VALUES 1, 2, 3, 4) AS t(c)</pre> Example result: `1`  | 
|  array\$1agg(x)  |  array<[same as input]  |  Returns an array created from the input x elements. <pre>SELECT array_agg(t.c) FROM (VALUES 1, 2, 3, 4) AS t(c)</pre> Example result: `[ 1,2,3,4 ]`  | 
|  avg(x)  |  double  |  Returns the average (arithmetic mean) of all input values. <pre>SELECT avg(t.c) FROM (VALUES 1, 2, 3, 4) AS t(c)</pre> Example result: `2.5`  | 
|  bool\$1and(boolean) every(boolean)   |  boolean  |  Returns TRUE if every input value is TRUE, otherwise FALSE. <pre>SELECT bool_and(t.c) FROM (VALUES true, true, false, true) AS t(c)</pre> Example result: `false`  | 
|  bool\$1or(boolean)  |  boolean  |  Returns TRUE if any input value is TRUE, otherwise FALSE. <pre>SELECT bool_or(t.c) FROM (VALUES true, true, false, true) AS t(c)</pre> Example result: `true`  | 
|  count(\$1) count(x)  |  bigint  |  count(\$1) returns the number of input rows. count(x) returns the number of non-null input values. <pre>SELECT count(t.c) FROM (VALUES true, true, false, true) AS t(c)</pre> Example result: `4`  | 
|  count\$1if(x)   |  bigint  |  Returns the number of TRUE input values.  <pre>SELECT count_if(t.c) FROM (VALUES true, true, false, true) AS t(c)</pre> Example result: `3`  | 
|  geometric\$1mean(x)  |  double  |  Returns the geometric mean of all input values. <pre>SELECT geometric_mean(t.c) FROM (VALUES 1, 2, 3, 4) AS t(c)</pre> Example result: `2.213363839400643`  | 
|  max\$1by(x, y)   |  [same as x]  |  Returns the value of x associated with the maximum value of y over all input values. <pre>SELECT max_by(t.c1, t.c2) FROM (VALUES (('a', 1)), (('b', 2)), (('c', 3)), (('d', 4))) AS t(c1, c2)</pre> Example result: `d`  | 
|  max\$1by(x, y, n)   |  array<[same as x]>  |  Returns n values of x associated with the n largest of all input values of y in descending order of y. <pre>SELECT max_by(t.c1, t.c2, 2) FROM (VALUES (('a', 1)), (('b', 2)), (('c', 3)), (('d', 4))) AS t(c1, c2)</pre> Example result: `[ d,c ]`  | 
|  min\$1by(x, y)  |  [same as x]  |  Returns the value of x associated with the minimum value of y over all input values. <pre>SELECT min_by(t.c1, t.c2) FROM (VALUES (('a', 1)), (('b', 2)), (('c', 3)), (('d', 4))) AS t(c1, c2)</pre> Example result: `a`  | 
|  min\$1by(x, y, n)  |  array<[same as x]>  |  Returns n values of x associated with the n smallest of all input values of y in ascending order of y. <pre>SELECT min_by(t.c1, t.c2, 2) FROM (VALUES (('a', 1)), (('b', 2)), (('c', 3)), (('d', 4))) AS t(c1, c2)</pre> Example result: `[ a,b ]`  | 
|  max(x)  |  [same as input]  |  Returns the maximum value of all input values. <pre>SELECT max(t.c) FROM (VALUES 1, 2, 3, 4) AS t(c)</pre> Example result: `4`  | 
|  max(x, n)  |  array<[same as x]>  |  Returns n largest values of all input values of x. <pre>SELECT max(t.c, 2) FROM (VALUES 1, 2, 3, 4) AS t(c)</pre> Example result: `[ 4,3 ]`  | 
|  min(x)  |  [same as input]  |  Returns the minimum value of all input values. <pre>SELECT min(t.c) FROM (VALUES 1, 2, 3, 4) AS t(c)</pre> Example result: `1`  | 
|  min(x, n)  |  array<[same as x]>  |  Returns n smallest values of all input values of x. <pre>SELECT min(t.c, 2) FROM (VALUES 1, 2, 3, 4) AS t(c)</pre> Example result: `[ 1,2 ]`  | 
|  sum(x)   |  [same as input]  |  Returns the sum of all input values. <pre>SELECT sum(t.c) FROM (VALUES 1, 2, 3, 4) AS t(c)</pre> Example result: `10`  | 
|  bitwise\$1and\$1agg(x)  |  bigint  |  Returns the bitwise AND of all input values in 2s complement representation. <pre>SELECT bitwise_and_agg(t.c) FROM (VALUES 1, -3) AS t(c)</pre> Example result: `1`  | 
|  bitwise\$1or\$1agg(x)  |  bigint  |  Returns the bitwise OR of all input values in 2s complement representation. <pre>SELECT bitwise_or_agg(t.c) FROM (VALUES 1, -3) AS t(c)</pre> Example result: `-3`  | 
|  approx\$1distinct(x)   |  bigint  |  Returns the approximate number of distinct input values. This function provides an approximation of count(DISTINCT x). Zero is returned if all input values are null. This function should produce a standard error of 2.3%, which is the standard deviation of the (approximately normal) error distribution over all possible sets. It does not guarantee an upper bound on the error for any specific input set. <pre>SELECT approx_distinct(t.c) FROM (VALUES 1, 2, 3, 4, 8) AS t(c)</pre> Example result: `5`  | 
|  approx\$1distinct(x, e)  |  bigint  |  Returns the approximate number of distinct input values. This function provides an approximation of count(DISTINCT x). Zero is returned if all input values are null. This function should produce a standard error of no more than e, which is the standard deviation of the (approximately normal) error distribution over all possible sets. It does not guarantee an upper bound on the error for any specific input set. The current implementation of this function requires that e be in the range of [0.0040625, 0.26000]. <pre>SELECT approx_distinct(t.c, 0.2) FROM (VALUES 1, 2, 3, 4, 8) AS t(c)</pre> Example result: `5`  | 
|  approx\$1percentile(x, percentage)   |  [same as x]  |  Returns the approximate percentile for all input values of x at the given percentage. The value of percentage must be between zero and one and must be constant for all input rows. <pre>SELECT approx_percentile(t.c, 0.4) FROM (VALUES 1, 2, 3, 4) AS t(c)</pre> Example result: `2`  | 
|  approx\$1percentile(x, percentages)   |  array<[same as x]>  |  Returns the approximate percentile for all input values of x at each of the specified percentages. Each element of the percentages array must be between zero and one, and the array must be constant for all input rows. <pre>SELECT approx_percentile(t.c, ARRAY[0.1, 0.8, 0.8]) FROM (VALUES 1, 2, 3, 4) AS t(c)</pre> Example result: `[ 1,4,4 ]`  | 
|  approx\$1percentile(x, w, percentage)   |  [same as x]  |  Returns the approximate weighed percentile for all input values of x using the per-item weight w at the percentage p. The weight must be an integer value of at least one. It is effectively a replication count for the value x in the percentile set. The value of p must be between zero and one and must be constant for all input rows. <pre>SELECT approx_percentile(t.c, 1, 0.1) FROM (VALUES 1, 2, 3, 4) AS t(c)</pre> Example result: `1`  | 
|  approx\$1percentile(x, w, percentages)   |  array<[same as x]>  |  Returns the approximate weighed percentile for all input values of x using the per-item weight w at each of the given percentages specified in the array. The weight must be an integer value of at least one. It is effectively a replication count for the value x in the percentile set. Each element of the array must be between zero and one, and the array must be constant for all input rows. <pre>SELECT approx_percentile(t.c, 1, ARRAY[0.1, 0.8, 0.8]) FROM (VALUES 1, 2, 3, 4) AS t(c)</pre> Example result: `[ 1,4,4 ]`  | 
|  approx\$1percentile(x, w, percentage, accuracy)  |  [same as x]  |  Returns the approximate weighed percentile for all input values of x using the per-item weight w at the percentage p, with a maximum rank error of accuracy. The weight must be an integer value of at least one. It is effectively a replication count for the value x in the percentile set. The value of p must be between zero and one and must be constant for all input rows. The accuracy must be a value greater than zero and less than one, and it must be constant for all input rows. <pre>SELECT approx_percentile(t.c, 1, 0.1, 0.5) FROM (VALUES 1, 2, 3, 4) AS t(c)</pre> Example result: `1`  | 
|  corr(y, x)  |  double  |  Returns correlation coefficient of input values. <pre>SELECT corr(t.c1, t.c2) FROM (VALUES ((1, 1)), ((2, 2)), ((3, 3)), ((4, 4))) AS t(c1, c2)</pre> Example result: `1.0`  | 
|  covar\$1pop(y, x)  |  double  |  Returns the population covariance of input values. <pre>SELECT covar_pop(t.c1, t.c2) FROM (VALUES ((1, 1)), ((2, 2)), ((3, 3)), ((4, 4))) AS t(c1, c2)</pre> Example result: `1.25`  | 
|  covar\$1samp(y, x)   |  double  |  Returns the sample covariance of input values. <pre>SELECT covar_samp(t.c1, t.c2) FROM (VALUES ((1, 1)), ((2, 2)), ((3, 3)), ((4, 4))) AS t(c1, c2)</pre> Example result: `1.6666666666666667`  | 
|  regr\$1intercept(y, x)  |  double  |  Returns linear regression intercept of input values. y is the dependent value. x is the independent value. <pre>SELECT regr_intercept(t.c1, t.c2) FROM (VALUES ((1, 1)), ((2, 2)), ((3, 3)), ((4, 4))) AS t(c1, c2)</pre> Example result: `0.0`  | 
|  regr\$1slope(y, x)  |  double  |  Returns linear regression slope of input values. y is the dependent value. x is the independent value. <pre>SELECT regr_slope(t.c1, t.c2) FROM (VALUES ((1, 1)), ((2, 2)), ((3, 3)), ((4, 4))) AS t(c1, c2)</pre> Example result: `1.0`  | 
|  skewness(x)  |  double  |  Returns the skewness of all input values. <pre>SELECT skewness(t.c1) FROM (VALUES 1, 2, 3, 4, 8) AS t(c1)</pre> Example result: `0.8978957037987335`  | 
|  stddev\$1pop(x)  |  double  |  Returns the population standard deviation of all input values. <pre>SELECT stddev_pop(t.c1) FROM (VALUES 1, 2, 3, 4, 8) AS t(c1)</pre> Example result: `2.4166091947189146`  | 
|  stddev\$1samp(x) stddev(x)  |  double  |  Returns the sample standard deviation of all input values. <pre>SELECT stddev_samp(t.c1) FROM (VALUES 1, 2, 3, 4, 8) AS t(c1)</pre> Example result: `2.701851217221259`  | 
|  var\$1pop(x)   |  double  |  Returns the population variance of all input values. <pre>SELECT var_pop(t.c1) FROM (VALUES 1, 2, 3, 4, 8) AS t(c1)</pre> Example result: `5.840000000000001`  | 
|  var\$1samp(x) variance(x)   |  double  |  Returns the sample variance of all input values. <pre>SELECT var_samp(t.c1) FROM (VALUES 1, 2, 3, 4, 8) AS t(c1)</pre> Example result: `7.300000000000001`  | 