Aggregate query is supported in TDengine by following aggregate functions and selection functions.
Aggregate queries are supported in TDengine by the following aggregate functions and selection functions.
### COUNT
...
...
@@ -12,11 +12,11 @@ Aggregate query is supported in TDengine by following aggregate functions and se
SELECT COUNT([*|field_name]) FROM tb_name [WHERE clause];
```
**Description**:Get the number of rows or the number of non-null values in a table or a super table.
**Description**:Get the number of rows or the number of non-null values in a table or a super table.
**Return value type**:Long integer INT64
**Return value type**:Long integer INT64
**Applicable column types**:All
**Applicable column types**:All
**Applicable table types**: table, super table, sub table
...
...
@@ -47,13 +47,13 @@ Query OK, 1 row(s) in set (0.001075s)
SELECT AVG(field_name) FROM tb_name [WHERE clause];
```
**Description**:Get the average value of a column in a table or STable
**Description**:Get the average value of a column in a table or STable
**Return value type**:Double precision floating number
**Return value type**:Double precision floating number
**Applicable column types**:Data types except for timestamp, binary, nchar and bool
**Applicable column types**:Data types except for timestamp, binary, nchar and bool
**Applicable table types**:table, STable
**Applicable table types**:table, STable
**Examples**:
...
...
@@ -77,13 +77,13 @@ Query OK, 1 row(s) in set (0.000943s)
SELECT TWA(field_name) FROM tb_name WHERE clause;
```
**Description**:Time weighted average on a specific column within a time range
**Description**:Time weighted average on a specific column within a time range
**Return value type**:Double precision floating number
**Return value type**:Double precision floating number
**Applicable column types**:Data types except for timestamp, binary, nchar and bool
**Applicable column types**:Data types except for timestamp, binary, nchar and bool
**Applicable table types**:table, STable
**Applicable table types**:table, STable
**More explanations**:
...
...
@@ -95,13 +95,13 @@ SELECT TWA(field_name) FROM tb_name WHERE clause;
SELECT IRATE(field_name) FROM tb_name WHERE clause;
```
**Description**:instantaneous rate on a specific column. The last two samples in the specified time range are used to calculate instantaneous rate. If the last sample value is smaller, then only the last sample value is used instead of the difference between the last two sample values.
**Description**:instantaneous rate on a specific column. The last two samples in the specified time range are used to calculate instantaneous rate. If the last sample value is smaller, then only the last sample value is used instead of the difference between the last two sample values.
**Return value type**:Double precision floating number
**Return value type**:Double precision floating number
**Applicable column types**:Data types except for timestamp, binary, nchar and bool
**Applicable column types**:Data types except for timestamp, binary, nchar and bool
**Applicable table types**:table, STable
**Applicable table types**:table, STable
**More explanations**:
...
...
@@ -113,13 +113,13 @@ SELECT IRATE(field_name) FROM tb_name WHERE clause;
SELECT SUM(field_name) FROM tb_name [WHERE clause];
```
**Description**:The sum of a specific column in a table or STable
**Description**:The sum of a specific column in a table or STable
**Return value type**:Double precision floating number or long integer
**Return value type**:Double precision floating number or long integer
**Applicable column types**:Data types except for timestamp, binary, nchar and bool
**Applicable column types**:Data types except for timestamp, binary, nchar and bool
**Applicable table types**:table, STable
**Applicable table types**:table, STable
**Examples**:
...
...
@@ -143,13 +143,13 @@ Query OK, 1 row(s) in set (0.000980s)
SELECT STDDEV(field_name) FROM tb_name [WHERE clause];
```
**Description**:Standard deviation of a specific column in a table or STable
**Description**:Standard deviation of a specific column in a table or STable
**Return value type**:Double precision floating number
**Return value type**:Double precision floating number
**Applicable column types**:Data types except for timestamp, binary, nchar and bool
**Applicable column types**:Data types except for timestamp, binary, nchar and bool
**Applicable table types**:table, STable (starting from version 2.0.15.1)
**Applicable table types**:table, STable (starting from version 2.0.15.1)
**Examples**:
...
...
@@ -187,7 +187,7 @@ Query OK, 1 row(s) in set (0.000921s)
## Selection Functions
When any selective function is used, timestamp column or tag columns including `tbname` can be specified to show that the selected value are from which rows.
When any select function is used, timestamp column or tag columns including `tbname` can be specified to show that the selected value are from which rows.
### MIN
...
...
@@ -195,13 +195,13 @@ When any selective function is used, timestamp column or tag columns including `
SELECT MIN(field_name) FROM {tb_name | stb_name} [WHERE clause];
```
**Description**:The minimum value of a specific column in a table or STable
**Description**:The minimum value of a specific column in a table or STable
**Return value type**:Same as the data type of the column being operated
**Return value type**:Same as the data type of the column being operated
**Applicable column types**:Data types except for timestamp, binary, nchar and bool
**Applicable column types**:Data types except for timestamp, binary, nchar and bool
**Applicable table types**:table, STable
**Applicable table types**:table, STable
**Examples**:
...
...
@@ -225,13 +225,13 @@ Query OK, 1 row(s) in set (0.000950s)
SELECT MAX(field_name) FROM { tb_name | stb_name } [WHERE clause];
```
**Description**:The maximum value of a specific column of a table or STable
**Description**:The maximum value of a specific column of a table or STable
**Return value type**:Same as the data type of the column being operated
**Return value type**:Same as the data type of the column being operated
**Applicable column types**:Data types except for timestamp, binary, nchar and bool
**Applicable column types**:Data types except for timestamp, binary, nchar and bool
**Applicable table types**:table, STable
**Applicable table types**:table, STable
**Examples**:
...
...
@@ -255,13 +255,13 @@ Query OK, 1 row(s) in set (0.000987s)
SELECT FIRST(field_name) FROM { tb_name | stb_name } [WHERE clause];
```
**Description**:The first non-null value of a specific column in a table or STable
**Description**:The first non-null value of a specific column in a table or STable
**Return value type**:Same as the column being operated
**Return value type**:Same as the column being operated
**Applicable column types**:Any data type
**Applicable column types**:Any data type
**Applicable table types**:table, STable
**Applicable table types**:table, STable
**More explanations**:
...
...
@@ -291,13 +291,13 @@ Query OK, 1 row(s) in set (0.001023s)
SELECT LAST(field_name) FROM { tb_name | stb_name } [WHERE clause];
```
**Description**:The last non-NULL value of a specific column in a table or STable
**Description**:The last non-NULL value of a specific column in a table or STable
**Return value type**:Same as the column being operated
**Return value type**:Same as the column being operated
**Description**: The greatest _k_ values of a specific column in a table or STable. If a value has multiple occurrences in the column but counting all of them in will exceed the upper limit _k_, then a part of them will be returned randomly.
**Return value type**:Same as the column being operated
**Return value type**:Same as the column being operated
**Applicable column types**:Data types except for timestamp, binary, nchar and bool
**Applicable column types**:Data types except for timestamp, binary, nchar and bool
**Applicable table types**:table, STable
**Applicable table types**:table, STable
**More explanations**:
...
...
@@ -366,9 +366,9 @@ Query OK, 2 row(s) in set (0.000810s)
**Description**:The least _k_ values of a specific column in a table or STable. If a value has multiple occurrences in the column but counting all of them in will exceed the upper limit _k_, then a part of them will be returned randomly.
**Description**:The least _k_ values of a specific column in a table or STable. If a value has multiple occurrences in the column but counting all of them in will exceed the upper limit _k_, then a part of them will be returned randomly.
**Return value type**:Same as the column being operated
**Return value type**:Same as the column being operated
**Applicable column types**: Data types except for timestamp, binary, nchar and bool
taos> SELECT INTERP(current) FROM t1 RANGE('2017-7-14 18:40:00','2017-7-14 18:40:00') FILL(LINEAR);
```
- Get an original data every 5 seconds, no interpolation, between "2017-07-14 18:00:00" and "2017-07-14 19:00:00:
- Get original data every 5 seconds, no interpolation, between "2017-07-14 18:00:00" and "2017-07-14 19:00:00:
```
taos> SELECT INTERP(current) FROM t1 RANGE('2017-7-14 18:00:00','2017-7-14 19:00:00') EVERY(5s);
...
...
@@ -588,7 +588,7 @@ SELECT INTERP(field_name) FROM { tb_name | stb_name } WHERE ts='timestamp' [FILL
Query OK, 1 row(s) in set (0.002652s)
```
If there is not any data corresponding to the specified timestamp, an interpolation value is returned if interpolation policy is specified by `FILL` parameter; or nothing is returned\
If there is no data corresponding to the specified timestamp, an interpolation value is returned if interpolation policy is specified by `FILL` parameter; or nothing is returned.
```
taos> SELECT INTERP(*) FROM meters WHERE tbname IN ('d636') AND ts='2017-7-14 18:40:00.005';
- It is available from version 2.1.3.0, the number of result rows is the number of total rows in the time range subtracted by one, no output for the first row.\
- It is available from version 2.1.3.0, the number of result rows is the number of total rows in the time range subtracted by one, no output for the first row.
- It can be used together with `GROUP BY tbname` against a STable.