Aggregate Functions¶
An aggregate function performs a calculation operation on a set of input values and returns a value. For example, the COUNT function counts the number of rows retrieved by an SQL statement. Table 1 lists aggregate functions.
Sample data: Table T1
|score|
|81 |
|100 |
|60 |
|95 |
|86 |
Common Aggregate Functions¶
Function | Return Data Type | Description |
---|---|---|
BIGINT | Return count of tuples. | |
BIGINT | Returns the number of input rows for which the expression is not NULL. Use DISTINCT for a unique instance of each value. | |
DOUBLE | Return average (arithmetic mean) of all input values. | |
DOUBLE | Return the sum of all input numerical values. | |
DOUBLE | Return the maximum value of all input values. | |
DOUBLE | Return the minimum value of all input values. | |
DOUBLE | Return the population standard deviation of all numeric fields of all input values. | |
DOUBLE | Return the sample standard deviation of all numeric fields of all input values. | |
DOUBLE | Return the population variance (square of population standard deviation) of numeral fields of all input values. | |
DOUBLE | Return the sample variance (square of the sample standard deviation) of numeric fields of all input values. |
Example¶
COUNT(*)
Test statement
SELECT COUNT(score) FROM T1;
Test data and results
¶ Test Data (score)
Test Result
81
5
100
60
95
86
COUNT([ ALL ] expression | DISTINCT expression1 [, expression2]*)
Test statement
SELECT COUNT(DISTINCT content ) FROM T1;
Test data and results
¶ content (STRING)
Test Result
"hello1 "
2
"hello2 "
"hello2"
null
86
AVG(numeric)
Test statement
SELECT AVG(score) FROM T1;
Test data and results
¶ Test Data (score)
Test Result
81
84.0
100
60
95
86
SUM(numeric)
Test statement
SELECT SUM(score) FROM T1;
Test data and results
¶ Test Data (score)
Test Result
81
422.0
100
60
95
86
MAX(value)
Test statement
SELECT MAX(score) FROM T1;
Test data and results
¶ Test Data (score)
Test Result
81
100.0
100
60
95
86
MIN(value)
Test statement
SELECT MIN(score) FROM T1;
Test data and results
¶ Test Data (score)
Test Result
81
60.0
100
60
95
86
STDDEV_POP(value)
Test statement
SELECT STDDEV_POP(score) FROM T1;
Test data and results
¶ Test Data (score)
Test Result
81
13.0
100
60
95
86
STDDEV_SAMP(value)
Test statement
SELECT STDDEV_SAMP(score) FROM T1;
Test data and results
¶ Test Data (score)
Test Result
81
15.0
100
60
95
86
VAR_POP(value)
Test statement
SELECT VAR_POP(score) FROM T1;
Test data and results
¶ Test Data (score)
Test Result
81
193.0
100
60
95
86
VAR_SAMP(value)
Test statement
SELECT VAR_SAMP(score) FROM T1;
Test data and results
¶ Test Data (score)
Test Result
81
241.0
100
60
95
86