SELECT TAIL(field_name, k, offset_val) FROM {tb_name | stb_name} [WHERE clause];
```
功能说明:返回跳过最后 offset_value个,然后取连续 k 个记录,不忽略 NULL 值。offset_val 可以不输入。此时返回最后的 k 个记录。当有 offset_val 输入的情况下,该函数功能等效于order by ts desc LIMIT k OFFSET offset_val。
@@ -852,6 +852,69 @@ TDengine supports aggregations over data, they are listed below:
...
@@ -852,6 +852,69 @@ TDengine supports aggregations over data, they are listed below:
Query OK, 1 row(s) in set (0.000921s)
Query OK, 1 row(s) in set (0.000921s)
```
```
-**MODE**
```mysql
SELECT MODE(field_name) FROM tb_name [WHERE clause];
```
Function: Returns the value with the highest frequency. If there are multiple highest values with the same frequency, the output is NULL.
Return Data Type: Same as applicable fields.
Applicable Fields: All types except timestamp.
Supported version: Version after 2.6.0 .
Example:
```mysql
taos> select voltage from d002;
voltage |
========================
1 |
1 |
2 |
19 |
Query OK, 4 row(s) in set (0.003545s)
taos> select mode(voltage) from d002;
mode(voltage) |
========================
1 |
Query OK, 1 row(s) in set (0.019393s)
```
- **HYPERLOGLOG**
```mysql
SELECT HYPERLOGLOG(field_name) FROM { tb_name | stb_name } [WHERE clause];
```
Function: The hyperloglog algorithm is used to return the cardinality of a column. In the case of large amount of data, the algorithm can significantly reduce the occupation of memory, but the cardinality is an estimated value, and the standard error is 0.81%.
Return Data Type:Integer.
Applicable Fields: All types.
Supported version: Version after 2.6.0 .
Example:
```mysql
taos> select dbig from shll;
dbig |
========================
1 |
1 |
1 |
NULL |
2 |
19 |
NULL |
9 |
Query OK, 8 row(s) in set (0.003755s)
taos> select hyperloglog(dbig) from shll;
hyperloglog(dbig)|
========================
4 |
Query OK, 1 row(s) in set (0.008388s)
### Selector Functions
### Selector Functions
-**MIN**
-**MIN**
...
@@ -1102,6 +1165,83 @@ TDengine supports aggregations over data, they are listed below:
...
@@ -1102,6 +1165,83 @@ TDengine supports aggregations over data, they are listed below:
Query OK, 1 row(s) in set (0.001042s)
Query OK, 1 row(s) in set (0.001042s)
```
```
-**TAIL**
```mysql
SELECT TAIL(field_name, k, offset_val) FROM {tb_name | stb_name} [WHERE clause];
```
Function: Skip the last num of offset_value, return the k consecutive records without ignoring NULL value. offset_val can be empty, then the last K records are returned.The function is equivalent to:order by ts desc LIMIT k OFFSET offset_val.
SELECT UNIQUE(field_name) FROM {tb_name | stb_name} [WHERE clause];
```
Function: Returns the first occurrence of a value in this column.
Return Data Type: Same as applicable fields.
Applicable Fields: All types except timestamp.
Applied to: **table stable**.
Supported version: Version after 2.6.0 .
Note: This function can be applied to ordinary tables and super tables. Cannot be used with window operations,such as interval/state_window/session_window.
Function: Returns the number of consecutive records that meet a certain condition, and the result is appended to each row as a new column. The condition is calculated according to the parameters. If the condition is true, it will be increased by 1. If the condition is false, it will be reset to -1. If the data is NULL, the data will be skipped.
Applicable Fields: All types except timestamp, binary, nchar, bool.
Supported version: Version after 2.6.0 .
Note:
- This function can be applied to ordinary tables. When a separate timeline is divided by group by, it is used for super tables (i.e. group by TBNAME).
- Cannot be used with window operations,such as interval/state_window/session_window.
Function: Returns the length of time of continuous records that meet a certain condition, and the result is appended to each row as a new column. The condition is calculated according to the parameters. If the condition is true, the length of time between two records will be added (the length of time of the first record that meets the condition is recorded as 0). If the condition is false, it will be reset to -1. If the data is NULL, the data will be skipped.
- unit : Unit of time length, range [1s, 1M, 1H], less than one unit is rounded off. The default is 1s.
Returned Data Type: Integer。
Applicable Fields: All types except timestamp, binary, nchar, bool.
Supported version: Version after 2.6.0 .
Note:
- This function can be applied to ordinary tables. When a separate timeline is divided by group by, it is used for super tables (i.e. group by TBNAME).
- Cannot be used with window operations,such as interval/state_window/session_window.
TDengine supports aggregating by intervals (time range). Data in a table can partitioned by intervals and aggregated to generate results. For example, a temperature sensor collects data once per second, but the average temperature needs to be queried every 10 minutes. This aggregation is suitable for down sample operation, and the syntax is as follows:
TDengine supports aggregating by intervals (time range). Data in a table can partitioned by intervals and aggregated to generate results. For example, a temperature sensor collects data once per second, but the average temperature needs to be queried every 10 minutes. This aggregation is suitable for down sample operation, and the syntax is as follows: