Aggregate Functions

Aggregate functions are many-to-one functions. They perform aggregate calculations on a set of values, resulting in a single aggregated result.

All aggregate functions except COUNT() ignore null values and return null when there are no input rows or all values are null. For example, SUM() returns null instead of zero, and AVG() does not include null values in the count.

The aggregate functions supported by IoTDB are as follows:

Function NameFunction DescriptionAllowed Input Data TypesOutput Data Types
SUMSummation.INT32 INT64 FLOAT DOUBLEDOUBLE
COUNTCounts the number of data points.All typesINT
AVGAverage.INT32 INT64 FLOAT DOUBLEDOUBLE
EXTREMEFinds the value with the largest absolute value. Returns a positive value if the maximum absolute value of positive and negative values is equal.INT32 INT64 FLOAT DOUBLEConsistent with the input data type
MAX_VALUEFind the maximum value.INT32 INT64 FLOAT DOUBLEConsistent with the input data type
MIN_VALUEFind the minimum value.INT32 INT64 FLOAT DOUBLEConsistent with the input data type
FIRST_VALUEFind the value with the smallest timestamp.All data typesConsistent with input data type
LAST_VALUEFind the value with the largest timestamp.All data typesConsistent with input data type
MAX_TIMEFind the maximum timestamp.All data TypesTimestamp
MIN_TIMEFind the minimum timestamp.All data TypesTimestamp

Example: Count Points

  1. select count(status) from root.ln.wf01.wt01;

Result:

  1. +-------------------------------+
  2. |count(root.ln.wf01.wt01.status)|
  3. +-------------------------------+
  4. | 10080|
  5. +-------------------------------+
  6. Total line number = 1
  7. It costs 0.016s