Statistical list aggregate functions
Use these functions to compute statistics over the elements of one list, such as the median, the mode, the variance, or the standard deviation. Functions whose names end in _pop treat the list as a whole population, and functions whose names end in _samp treat it as a sample.
list_entropy function
Treats the non-NULL elements of list as a sample and returns the Shannon entropy of how often each distinct value occurs, computed with base-2 logarithms. The result is 0 when every element has the same value, and it grows as the values become more varied and more evenly spread. For n distinct values that each occur equally often, the result is the base-2 logarithm of n.
NULL elements are ignored. If list is NULL, the result is NULL. list_entropy( returns the same result as list)list_aggregate(.list, 'entropy')
Syntax
list_entropy(list)
Arguments
The list_entropy function takes the following argument:
list-
The list whose entropy you want, such as an
INTEGER[]orVARCHAR[]value. Its elements must be values that can be compared for equality.
Return type
DOUBLE
Examples
The following SQL query returns the entropy of a list in which one value occurs twice and another occurs once.
SELECT list_entropy([3, 3, 9]) AS result
The query returns the following result.
| result |
|---|
|
The following SQL query compares a list of four different values, which has an entropy of 2 bits, with a list in which every value is the same.
SELECT list_entropy([1, 2, 3, 4]) AS four_values, list_entropy(['x', 'x', 'x']) AS one_value
The query returns the following result.
| four_values | one_value |
|---|---|
|
|
The following SQL query shows that an empty list returns 0.
SELECT list_entropy(CAST([] AS INTEGER[])) AS result
The query returns the following result.
| result |
|---|
|
Considerations
An empty list, or a list that holds only NULL elements, returns 0, not NULL.
list_kurtosis function
Returns the sample excess kurtosis of the elements of list that are not NULL. Kurtosis measures how heavy the tails of a distribution are. Excess kurtosis subtracts 3, so a normal distribution scores 0, a distribution with more extreme outliers scores higher, and a distribution with fewer scores lower. The sample form treats the elements as a sample drawn from a larger set of values, and it applies a correction for the number of elements.
The function needs at least four elements that are not NULL. With fewer elements, or when every element has the same value, the result is NULL.
list_kurtosis( returns the same result as list)list_aggregate(. To compute the kurtosis of the elements as a whole population, without the correction, use the list_kurtosis_pop function. To compute kurtosis across rows, use the list, 'kurtosis')kurtosis aggregate function.
Syntax
list_kurtosis(list)
Arguments
The list_kurtosis function takes the following argument:
list-
The list of numbers whose sample excess kurtosis you want. The elements are converted to
DOUBLE.
Return type
DOUBLE
Examples
The following SQL query returns the sample excess kurtosis of four numbers.
SELECT list_kurtosis([1, 2, 2, 3]) AS result
The query returns the following result.
| result |
|---|
|
The following SQL query shows that a NULL element is ignored, so the result is the same as for the four other numbers.
SELECT list_kurtosis([1, 2, 2, 3, NULL]) AS result
The query returns the following result.
| result |
|---|
|
The following SQL query returns NULL because the list has only three elements.
SELECT list_kurtosis([3, 3, 9]) AS result
The query returns the following result.
| result |
|---|
|
list_kurtosis_pop function
Returns the excess kurtosis of the elements of list that are not NULL, treating them as a whole population. Unlike list_kurtosis, the function makes no correction for the sample size. Excess kurtosis subtracts 3, so a normal distribution scores 0.
The function needs at least two elements that are not NULL. With fewer elements, or when every element has the same value, the result is NULL.
list_kurtosis_pop( returns the same result as list)list_aggregate(. To compute it across rows, use the list, 'kurtosis_pop')kurtosis_pop aggregate function.
Syntax
list_kurtosis_pop(list)
Arguments
The list_kurtosis_pop function takes the following argument:
list-
The list of numbers whose population excess kurtosis you want. The elements are converted to
DOUBLE.
Return type
DOUBLE
Examples
The following SQL query returns the population excess kurtosis of three numbers.
SELECT list_kurtosis_pop([3, 3, 9]) AS result
The query returns the following result.
| result |
|---|
|
The following SQL query compares the population and sample results for the same four numbers.
SELECT list_kurtosis_pop([1, 2, 2, 3]) AS population, list_kurtosis([1, 2, 2, 3]) AS sample
The query returns the following result.
| population | sample |
|---|---|
|
|
The following SQL query returns NULL because every element has the same value.
SELECT list_kurtosis_pop([5, 5, 5]) AS result
The query returns the following result.
| result |
|---|
|
list_mad function
Returns the median absolute deviation (MAD) of the elements of list: the median of the absolute differences between each element and the median of all the elements. Like the standard deviation, it measures how spread out the values are, but a few extreme values change it much less.
NULL elements are ignored. If list is empty, holds only NULL elements, or is NULL, the result is NULL. For a list of date or time values, the result is an INTERVAL.
list_mad( returns the same result as list)list_aggregate(. To compute it across rows, use the list, 'mad')mad aggregate function.
Syntax
list_mad(list)
Arguments
The list_mad function takes the following argument:
list-
The values whose median absolute deviation you want, as a list of numbers, or of
DATE,TIME,TIME WITH TIME ZONE,TIMESTAMP, orTIMESTAMP WITH TIME ZONEvalues.
Return type
DOUBLE for a list of integers or DOUBLE values, the element type for a list of FLOAT or DECIMAL values, and INTERVAL for a list of date or time values.
Examples
The following SQL query returns the median absolute deviation of three numbers. The median is 3, the absolute differences from it are 0, 0, and 6, and the median of those differences is 0.
SELECT list_mad([3, 3, 9]) AS result
The query returns the following result.
| result |
|---|
|
The following SQL query shows that one extreme value, 100, has little effect on the result.
SELECT list_mad([1, 2, 3, 4, 100]) AS result
The query returns the following result.
| result |
|---|
|
The following SQL query returns the median absolute deviation of three dates, as an INTERVAL.
SELECT list_mad( [ DATE '2026-10-01', DATE '2026-10-03', DATE '2026-10-10' ] ) AS result
The query returns the following result.
| result |
|---|
|
list_median function
Returns the median of the elements of list that are not NULL: the value in the middle when the elements are sorted. When there is an even number of elements, the result for numbers, dates, times, and intervals is the average of the two middle values. For other types, such as VARCHAR, it is the smaller of the two middle values.
If list is empty, holds only NULL elements, or is NULL, the result is NULL.
list_median( returns the same result as list)list_aggregate(. To compute the median across rows, use the list, 'median')median aggregate function.
Syntax
list_median(list)
Arguments
The list_median function takes the following argument:
list-
The list whose median you want, with elements of any type that can be ordered.
Return type
DOUBLE for a list of integers, TIMESTAMP for a list of DATE values, and the element type for other lists, including DECIMAL and VARCHAR lists.
Examples
The following SQL query returns the median of three integers.
SELECT list_median([3, 3, 9]) AS result
The query returns the following result.
| result |
|---|
|
The following SQL query returns the median of four integers and the median of four strings. For the integers, the median is the average of the two middle values. For the strings, it is the smaller of the two middle strings.
SELECT list_median([1, 2, 3, 4]) AS median_number, list_median(['b', 'a', 'c', 'd']) AS median_string
The query returns the following result.
| median_number | median_string |
|---|---|
|
|
The following SQL query returns the median of two dates. The average falls at noon, so the result is a TIMESTAMP.
SELECT list_median( [DATE '2026-10-01', DATE '2026-10-04'] ) AS result
The query returns the following result.
| result |
|---|
|
The following SQL query shows that the median of two DECIMAL(2,1) values keeps one decimal place and drops the rest. Cast the list to DOUBLE[] to get the exact average.
SELECT list_median([1.0, 2.5]) AS decimal_result, list_median( CAST([1.0, 2.5] AS DOUBLE[]) ) AS double_result
The query returns the following result.
| decimal_result | double_result |
|---|---|
|
|
Considerations
For a list of DATE values, the result is a TIMESTAMP, because the average of two dates can fall in the middle of a day.
For a list of DECIMAL values, the result has the same scale as the elements, and the digits past that scale are dropped, not rounded. For example, list_median([1.0, 2.5]) returns 1.7, not 1.75. To keep those digits, cast the list to DOUBLE[] first.
list_mode function
Returns the element of list that occurs most often. NULL elements are not counted, even when NULL occurs more often than any other element. If list is empty, holds only NULL elements, or is NULL, the result is NULL.
When two or more elements tie for the highest count, the result is the one that occurs first in the list.
list_mode( returns the same result as list)list_aggregate(. To find the most frequent value across rows, use the list, 'mode')mode aggregate function.
Syntax
list_mode(list)
Arguments
The list_mode function takes the following argument:
list-
The list whose most frequent element you want, with elements of any type.
Return type
The element type of list, for example INTEGER for an INTEGER[] list.
Examples
The following SQL query returns the most frequent element of a list.
SELECT list_mode([3, 3, 9]) AS result
The query returns the following result.
| result |
|---|
|
The following SQL query shows that NULL elements are not counted, even though NULL occurs most often.
SELECT list_mode([NULL, NULL, 4]) AS result
The query returns the following result.
| result |
|---|
|
The following SQL query shows how a tie is decided. In both lists, 1 and 2 each occur twice, so the result is the element that occurs first.
SELECT list_mode([2, 1, 1, 2]) AS starts_with_2, list_mode([1, 2, 2, 1]) AS starts_with_1
The query returns the following result.
| starts_with_2 | starts_with_1 |
|---|---|
|
|
list_sem function
Returns the standard error of the mean of the elements of list, computed as their population standard deviation divided by the square root of the number of elements. The result equals list_stddev_pop(, where list) / sqrt(n)n is the number of elements that are not NULL.
NULL elements are ignored. With one element, the result is 0.0. If the list is empty, contains only NULL elements, or is NULL, the result is NULL.
list_sem( returns the same result as list)list_aggregate(. To compute the value across rows, use the list, 'sem')sem aggregate function.
Syntax
list_sem(list)
Arguments
The list_sem function takes the following argument:
list-
The list of numeric values whose standard error of the mean you want. The values are converted to
DOUBLE.
Return type
DOUBLE
Examples
The following SQL query returns the standard error of the mean of three values.
SELECT list_sem([3, 3, 9]) AS result
The query returns the following result.
| result |
|---|
|
The following SQL query shows that the result equals the population standard deviation divided by the square root of the number of elements.
SELECT list_sem([3, 3, 9]) = list_stddev_pop([3, 3, 9]) / sqrt(3) AS is_equal
The query returns the following result.
| is_equal |
|---|
|
The following SQL query passes a list with one element, so the result is 0.0.
SELECT list_sem([5]) AS result
The query returns the following result.
| result |
|---|
|
Considerations
list_sem uses the population standard deviation. Some statistics tools compute the standard error with the sample standard deviation instead, which gives a larger value. For example, for [3, 3, 9], list_sem returns about 1.633, and list_stddev_samp([3, 3, 9]) / sqrt(3) returns 2.0.
list_skewness function
Returns the sample skewness of the elements of list, adjusted for the number of elements (the adjusted Fisher-Pearson coefficient of skewness). The value measures how asymmetric the distribution of the elements is. A positive result means a longer tail of large values, and a negative result means a longer tail of small values.
NULL elements are ignored. If the list has fewer than three elements that are not NULL, or if all of those elements are equal, the result is NULL.
list_skewness( returns the same result as list)list_aggregate(. To compute the value across rows, use the list, 'skewness')skewness aggregate function.
Syntax
list_skewness(list)
Arguments
The list_skewness function takes the following argument:
list-
The list of numeric values whose skewness you want. The values are converted to
DOUBLE.
Return type
DOUBLE
Examples
The following SQL query has one value that is larger than the others, so the skewness is positive.
SELECT list_skewness([3, 3, 9]) AS result
The query returns the following result.
| result |
|---|
|
The following SQL query returns the skewness of four values.
SELECT list_skewness([1, 1, 1, 5]) AS result
The query returns the following result.
| result |
|---|
|
The following SQL query passes only two elements, so the result is NULL.
SELECT list_skewness([1, 2]) AS result
The query returns the following result.
| result |
|---|
|
Differences from Athena engine version 3
Athena engine version 3 has no list_skewness function, and its skewness aggregate function does not adjust the result for the number of values. For the values 1, 1, 1, and 5, the skewness aggregate in Athena engine version 3 returns about 1.1547, and list_skewness([1, 1, 1, 5]) returns 2.0. To get the Athena engine version 3 value, multiply the result by (n - 2) / sqrt(n * (n - 1)), where n is the number of elements that are not NULL.
list_stddev_pop function
Returns the population standard deviation of the elements of list. It treats the elements as the whole population, so it divides the sum of squared deviations from the mean by the number of elements. To treat the elements as a sample of a larger population, use the list_stddev_samp function.
NULL elements are ignored. With one element, the result is 0.0. If the list is empty, contains only NULL elements, or is NULL, the result is NULL.
list_stddev_pop( returns the same result as list)list_aggregate(. To compute the value across rows, use the list, 'stddev_pop')stddev_pop aggregate function.
Syntax
list_stddev_pop(list)
Arguments
The list_stddev_pop function takes the following argument:
list-
The list of numeric values whose population standard deviation you want. The values are converted to
DOUBLE.
Return type
DOUBLE
Examples
The following SQL query returns the population standard deviation of three values.
SELECT list_stddev_pop([3, 3, 9]) AS result
The query returns the following result.
| result |
|---|
|
The following SQL query returns the population standard deviation of eight values, whose mean is 5.
SELECT list_stddev_pop([2, 4, 4, 4, 5, 5, 7, 9]) AS result
The query returns the following result.
| result |
|---|
|
The following SQL query ignores the NULL element and uses the other two values.
SELECT list_stddev_pop([3, NULL, 9]) AS result
The query returns the following result.
| result |
|---|
|
list_stddev_samp function
Returns the sample standard deviation of the elements of list. It treats the elements as a sample of a larger population, so it divides the sum of squared deviations from the mean by one less than the number of elements. To treat the elements as the whole population, use the list_stddev_pop function.
NULL elements are ignored. If the list has fewer than two elements that are not NULL, or if the list is NULL, the result is NULL.
list_stddev_samp( returns the same result as list)list_aggregate(. To compute the value across rows, use the list, 'stddev_samp')stddev_samp aggregate function.
Syntax
list_stddev_samp(list)
Arguments
The list_stddev_samp function takes the following argument:
list-
The list of numeric values whose sample standard deviation you want. The values are converted to
DOUBLE.
Return type
DOUBLE
Examples
The following SQL query returns the sample standard deviation of three values.
SELECT list_stddev_samp([3, 3, 9]) AS result
The query returns the following result.
| result |
|---|
|
The following SQL query returns the sample standard deviation of eight values, whose mean is 5.
SELECT list_stddev_samp([2, 4, 4, 4, 5, 5, 7, 9]) AS result
The query returns the following result.
| result |
|---|
|
The following SQL query passes a list with one element, so the result is NULL.
SELECT list_stddev_samp([5]) AS result
The query returns the following result.
| result |
|---|
|
list_var_pop function
Returns the population variance of the elements of list that are not NULL: the average of the squared differences between each element and the mean of the elements. The function divides by the number of elements, n, so for a list with one element, the result is 0.
NULL elements are skipped. If list is empty, holds only NULL elements, or is itself NULL, the result is NULL. list_var_pop( returns the same result as list)list_aggregate(. To estimate the variance of a larger population from a sample, use the list_var_samp function.list, 'var_pop')
Syntax
list_var_pop(list)
Arguments
The list_var_pop function takes the following argument:
list-
The numbers whose population variance you want, as a
LIST. The elements are converted toDOUBLEfor the computation.
Return type
DOUBLE
Examples
The following SQL query returns the population variance of three numbers, whose mean is 5.
SELECT list_var_pop([3, 3, 9]) AS result
The query returns the following result.
| result |
|---|
|
The following SQL query returns the population variance of the list [3, NULL, 3, 9]. The NULL element is skipped, so the result is 8.0, the same as for [3, 3, 9].
SELECT list_var_pop([3, NULL, 3, 9]) AS result
The query returns the following result.
| result |
|---|
|
The following SQL query shows that the population variance is 0.0 for a list with one element and NULL for an empty list.
SELECT list_var_pop([5]) AS one_element, list_var_pop([]) IS NULL AS empty_is_null
The query returns the following result.
| one_element | empty_is_null |
|---|---|
|
|
list_var_samp function
Returns the sample variance of the elements of list that are not NULL. The sample variance is the sum of the squared differences between each element and the mean, divided by the number of elements minus 1 (n - 1). Use it to estimate the variance of a population from a sample of its values.
NULL elements are skipped. If fewer than two elements are not NULL, the result is NULL, so a list with one element returns NULL, not 0. list_var_samp( returns the same result as list)list_aggregate(. For the population variance, use the list_var_pop function.list, 'var_samp')
Syntax
list_var_samp(list)
Arguments
The list_var_samp function takes the following argument:
list-
The numbers whose sample variance you want, as a
LIST. The elements are converted toDOUBLEfor the computation.
Return type
DOUBLE
Examples
The following SQL query returns the sample variance of three numbers.
SELECT list_var_samp([3, 3, 9]) AS result
The query returns the following result.
| result |
|---|
|
The following SQL query compares the population variance and the sample variance of the same list.
SELECT list_var_pop([1, 2, 3, 4]) AS population, list_var_samp([1, 2, 3, 4]) AS sample
The query returns the following result.
| population | sample |
|---|---|
|
|
The following SQL query shows that the sample variance of a list with one element is NULL.
SELECT list_var_samp([5]) IS NULL AS one_element_is_null
The query returns the following result.
| one_element_is_null |
|---|
|