未验证 提交 c2f23f83 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #17085 from taosdata/3.0

release: build 3.0.1.3
......@@ -13,7 +13,7 @@ Single row functions return a result for each row.
#### ABS
```sql
SELECT ABS(field_name) FROM { tb_name | stb_name } [WHERE clause]
ABS(expr)
```
**Description**: The absolute value of a specific field.
......@@ -31,7 +31,7 @@ SELECT ABS(field_name) FROM { tb_name | stb_name } [WHERE clause]
#### ACOS
```sql
SELECT ACOS(field_name) FROM { tb_name | stb_name } [WHERE clause]
ACOS(expr)
```
**Description**: The arc cosine of a specific field.
......@@ -49,7 +49,7 @@ SELECT ACOS(field_name) FROM { tb_name | stb_name } [WHERE clause]
#### ASIN
```sql
SELECT ASIN(field_name) FROM { tb_name | stb_name } [WHERE clause]
ASIN(expr)
```
**Description**: The arc sine of a specific field.
......@@ -68,7 +68,7 @@ SELECT ASIN(field_name) FROM { tb_name | stb_name } [WHERE clause]
#### ATAN
```sql
SELECT ATAN(field_name) FROM { tb_name | stb_name } [WHERE clause]
ATAN(expr)
```
**Description**: The arc tangent of a specific field.
......@@ -87,7 +87,7 @@ SELECT ATAN(field_name) FROM { tb_name | stb_name } [WHERE clause]
#### CEIL
```sql
SELECT CEIL(field_name) FROM { tb_name | stb_name } [WHERE clause];
CEIL(expr)
```
**Description**: The rounded up value of a specific field
......@@ -105,7 +105,7 @@ SELECT CEIL(field_name) FROM { tb_name | stb_name } [WHERE clause];
#### COS
```sql
SELECT COS(field_name) FROM { tb_name | stb_name } [WHERE clause]
COS(expr)
```
**Description**: The cosine of a specific field.
......@@ -123,7 +123,7 @@ SELECT COS(field_name) FROM { tb_name | stb_name } [WHERE clause]
#### FLOOR
```sql
SELECT FLOOR(field_name) FROM { tb_name | stb_name } [WHERE clause];
FLOOR(expr)
```
**Description**: The rounded down value of a specific field
......@@ -132,7 +132,7 @@ SELECT FLOOR(field_name) FROM { tb_name | stb_name } [WHERE clause];
#### LOG
```sql
SELECT LOG(field_name[, base]) FROM { tb_name | stb_name } [WHERE clause]
LOG(expr [, base])
```
**Description**: The logarithm of a specific field with `base` as the radix. If you do not enter a base, the natural logarithm of the field is returned.
......@@ -151,7 +151,7 @@ SELECT LOG(field_name[, base]) FROM { tb_name | stb_name } [WHERE clause]
#### POW
```sql
SELECT POW(field_name, power) FROM { tb_name | stb_name } [WHERE clause]
POW(expr, power)
```
**Description**: The power of a specific field with `power` as the exponent.
......@@ -170,7 +170,7 @@ SELECT POW(field_name, power) FROM { tb_name | stb_name } [WHERE clause]
#### ROUND
```sql
SELECT ROUND(field_name) FROM { tb_name | stb_name } [WHERE clause];
ROUND(expr)
```
**Description**: The rounded value of a specific field.
......@@ -180,7 +180,7 @@ SELECT ROUND(field_name) FROM { tb_name | stb_name } [WHERE clause];
#### SIN
```sql
SELECT SIN(field_name) FROM { tb_name | stb_name } [WHERE clause]
SIN(expr)
```
**Description**: The sine of a specific field.
......@@ -198,7 +198,7 @@ SELECT SIN(field_name) FROM { tb_name | stb_name } [WHERE clause]
#### SQRT
```sql
SELECT SQRT(field_name) FROM { tb_name | stb_name } [WHERE clause]
SQRT(expr)
```
**Description**: The square root of a specific field.
......@@ -216,7 +216,7 @@ SELECT SQRT(field_name) FROM { tb_name | stb_name } [WHERE clause]
#### TAN
```sql
SELECT TAN(field_name) FROM { tb_name | stb_name } [WHERE clause]
TAN(expr)
```
**Description**: The tangent of a specific field.
......@@ -238,7 +238,7 @@ Concatenation functions take strings as input and produce string or numeric valu
#### CHAR_LENGTH
```sql
SELECT CHAR_LENGTH(str|column) FROM { tb_name | stb_name } [WHERE clause]
CHAR_LENGTH(expr)
```
**Description**: The length in number of characters of a string
......@@ -254,7 +254,7 @@ SELECT CHAR_LENGTH(str|column) FROM { tb_name | stb_name } [WHERE clause]
#### CONCAT
```sql
SELECT CONCAT(str1|column1, str2|column2, ...) FROM { tb_name | stb_name } [WHERE clause]
CONCAT(expr1, expr2 [, expr] ...)
```
**Description**: The concatenation result of two or more strings
......@@ -271,7 +271,7 @@ SELECT CONCAT(str1|column1, str2|column2, ...) FROM { tb_name | stb_name } [WHER
#### CONCAT_WS
```sql
SELECT CONCAT_WS(separator, str1|column1, str2|column2, ...) FROM { tb_name | stb_name } [WHERE clause]
CONCAT_WS(separator_expr, expr1, expr2 [, expr] ...)
```
**Description**: The concatenation result of two or more strings with separator
......@@ -288,7 +288,7 @@ SELECT CONCAT_WS(separator, str1|column1, str2|column2, ...) FROM { tb_name | st
#### LENGTH
```sql
SELECT LENGTH(str|column) FROM { tb_name | stb_name } [WHERE clause]
LENGTH(expr)
```
**Description**: The length in bytes of a string
......@@ -305,7 +305,7 @@ SELECT LENGTH(str|column) FROM { tb_name | stb_name } [WHERE clause]
#### LOWER
```sql
SELECT LOWER(str|column) FROM { tb_name | stb_name } [WHERE clause]
LOWER(expr)
```
**Description**: Convert the input string to lower case
......@@ -322,7 +322,7 @@ SELECT LOWER(str|column) FROM { tb_name | stb_name } [WHERE clause]
#### LTRIM
```sql
SELECT LTRIM(str|column) FROM { tb_name | stb_name } [WHERE clause]
LTRIM(expr)
```
**Description**: Remove the left leading blanks of a string
......@@ -339,7 +339,7 @@ SELECT LTRIM(str|column) FROM { tb_name | stb_name } [WHERE clause]
#### RTRIM
```sql
SELECT LTRIM(str|column) FROM { tb_name | stb_name } [WHERE clause]
LTRIM(expr)
```
**Description**: Remove the right tailing blanks of a string
......@@ -356,7 +356,7 @@ SELECT LTRIM(str|column) FROM { tb_name | stb_name } [WHERE clause]
#### SUBSTR
```sql
SELECT SUBSTR(str,pos[,len]) FROM { tb_name | stb_name } [WHERE clause]
SUBSTR(expr, pos [, len])
```
**Description**: The sub-string starting from `pos` with length of `len` from the original string `str` - If `len` is not specified, it means from `pos` to the end.
......@@ -373,7 +373,7 @@ SELECT SUBSTR(str,pos[,len]) FROM { tb_name | stb_name } [WHERE clause]
#### UPPER
```sql
SELECT UPPER(str|column) FROM { tb_name | stb_name } [WHERE clause]
UPPER(expr)
```
**Description**: Convert the input string to upper case
......@@ -394,10 +394,10 @@ Conversion functions change the data type of a value.
#### CAST
```sql
SELECT CAST(expression AS type_name) FROM { tb_name | stb_name } [WHERE clause]
CAST(expr AS type_name)
```
**Description**: Convert the input data `expression` into the type specified by `type_name`. This function can be used only in SELECT statements.
**Description**: Convert the input data `expr` into the type specified by `type_name`. This function can be used only in SELECT statements.
**Return value type**: The type specified by parameter `type_name`
......@@ -418,7 +418,7 @@ SELECT CAST(expression AS type_name) FROM { tb_name | stb_name } [WHERE clause]
#### TO_ISO8601
```sql
SELECT TO_ISO8601(ts[, timezone]) FROM { tb_name | stb_name } [WHERE clause];
TO_ISO8601(expr [, timezone])
```
**Description**: The ISO8601 date/time format converted from a UNIX timestamp, plus the timezone. You can specify any time zone with the timezone parameter. If you do not enter this parameter, the time zone on the client is used.
......@@ -441,7 +441,7 @@ SELECT TO_ISO8601(ts[, timezone]) FROM { tb_name | stb_name } [WHERE clause];
#### TO_JSON
```sql
SELECT TO_JSON(str_literal) FROM { tb_name | stb_name } [WHERE clause];
TO_JSON(str_literal)
```
**Description**: Converts a string into JSON.
......@@ -458,7 +458,7 @@ SELECT TO_JSON(str_literal) FROM { tb_name | stb_name } [WHERE clause];
#### TO_UNIXTIMESTAMP
```sql
SELECT TO_UNIXTIMESTAMP(datetime_string) FROM { tb_name | stb_name } [WHERE clause];
TO_UNIXTIMESTAMP(expr)
```
**Description**: UNIX timestamp converted from a string of date/time format
......@@ -486,9 +486,7 @@ All functions that return the current time, such as `NOW`, `TODAY`, and `TIMEZON
#### NOW
```sql
SELECT NOW() FROM { tb_name | stb_name } [WHERE clause];
SELECT select_expr FROM { tb_name | stb_name } WHERE ts_col cond_operatior NOW();
INSERT INTO tb_name VALUES (NOW(), ...);
NOW()
```
**Description**: The current time of the client side system
......@@ -511,7 +509,7 @@ INSERT INTO tb_name VALUES (NOW(), ...);
#### TIMEDIFF
```sql
SELECT TIMEDIFF(ts | datetime_string1, ts | datetime_string2 [, time_unit]) FROM { tb_name | stb_name } [WHERE clause];
TIMEDIFF(expr1, expr2 [, time_unit])
```
**Description**: The difference between two timestamps, and rounded to the time unit specified by `time_unit`
......@@ -534,7 +532,7 @@ SELECT TIMEDIFF(ts | datetime_string1, ts | datetime_string2 [, time_unit]) FROM
#### TIMETRUNCATE
```sql
SELECT TIMETRUNCATE(ts | datetime_string , time_unit) FROM { tb_name | stb_name } [WHERE clause];
TIMETRUNCATE(expr, time_unit)
```
**Description**: Truncate the input timestamp with unit specified by `time_unit`
......@@ -555,7 +553,7 @@ SELECT TIMETRUNCATE(ts | datetime_string , time_unit) FROM { tb_name | stb_name
#### TIMEZONE
```sql
SELECT TIMEZONE() FROM { tb_name | stb_name } [WHERE clause];
TIMEZONE()
```
**Description**: The timezone of the client side system
......@@ -570,9 +568,7 @@ SELECT TIMEZONE() FROM { tb_name | stb_name } [WHERE clause];
#### TODAY
```sql
SELECT TODAY() FROM { tb_name | stb_name } [WHERE clause];
SELECT select_expr FROM { tb_name | stb_name } WHERE ts_col cond_operatior TODAY()];
INSERT INTO tb_name VALUES (TODAY(), ...);
TODAY()
```
**Description**: The timestamp of 00:00:00 of the client side system
......@@ -599,7 +595,12 @@ TDengine supports the following aggregate functions:
### APERCENTILE
```sql
SELECT APERCENTILE(field_name, P[, algo_type]) FROM { tb_name | stb_name } [WHERE clause]
APERCENTILE(expr, p [, algo_type])
algo_type: {
"default"
| "t-digest"
}
```
**Description**: Similar to `PERCENTILE`, but a simulated result is returned
......@@ -611,14 +612,14 @@ SELECT APERCENTILE(field_name, P[, algo_type]) FROM { tb_name | stb_name } [WHER
**Applicable table types**: standard tables and supertables
**Explanations**
- _P_ is in range [0,100], when _P_ is 0, the result is same as using function MIN; when _P_ is 100, the result is same as function MAX.
- _p_ is in range [0,100], when _p_ is 0, the result is same as using function MIN; when _p_ is 100, the result is same as function MAX.
- `algo_type` can only be input as `default` or `t-digest` Enter `default` to use a histogram-based algorithm. Enter `t-digest` to use the t-digest algorithm to calculate the approximation of the quantile. `default` is used by default.
- The approximation result of `t-digest` algorithm is sensitive to input data order. For example, when querying STable with different input data order there might be minor differences in calculated results.
### AVG
```sql
SELECT AVG(field_name) FROM tb_name [WHERE clause];
AVG(expr)
```
**Description**: The average value of the specified fields.
......@@ -633,7 +634,7 @@ SELECT AVG(field_name) FROM tb_name [WHERE clause];
### COUNT
```sql
SELECT COUNT([*|field_name]) FROM tb_name [WHERE clause];
COUNT({* | expr})
```
**Description**: The number of records in the specified fields.
......@@ -653,7 +654,7 @@ If you input a specific column, the number of non-null values in the column is r
### ELAPSED
```sql
SELECT ELAPSED(ts_primary_key [, time_unit]) FROM { tb_name | stb_name } [WHERE clause] [INTERVAL(interval [, offset]) [SLIDING sliding]];
ELAPSED(ts_primary_key [, time_unit])
```
**Description**`elapsed` function can be used to calculate the continuous time length in which there is valid data. If it's used with `INTERVAL` clause, the returned result is the calcualted time length within each time window. If it's used without `INTERVAL` caluse, the returned result is the calculated time length within the specified time range. Please be noted that the return value of `elapsed` is the number of `time_unit` in the calculated time length.
......@@ -665,7 +666,7 @@ SELECT ELAPSED(ts_primary_key [, time_unit]) FROM { tb_name | stb_name } [WHERE
**Applicable tables**: table, STable, outter in nested query
**Explanations**
- `field_name` parameter can only be the first column of a table, i.e. timestamp primary key.
- `ts_primary_key` parameter can only be the first column of a table, i.e. timestamp primary key.
- The minimum value of `time_unit` is the time precision of the database. If `time_unit` is not specified, the time precision of the database is used as the default time unit. Time unit specified by `time_unit` can be:
1b (nanoseconds), 1u (microseconds), 1a (milliseconds), 1s (seconds), 1m (minutes), 1h (hours), 1d (days), or 1w (weeks)
- It can be used with `INTERVAL` to get the time valid time length of each time window. Please be noted that the return value is same as the time window for all time windows except for the first and the last time window.
......@@ -679,7 +680,7 @@ SELECT ELAPSED(ts_primary_key [, time_unit]) FROM { tb_name | stb_name } [WHERE
### LEASTSQUARES
```sql
SELECT LEASTSQUARES(field_name, start_val, step_val) FROM tb_name [WHERE clause];
LEASTSQUARES(expr, start_val, step_val)
```
**Description**: The linear regression function of the specified column and the timestamp column (primary key), `start_val` is the initial value and `step_val` is the step value.
......@@ -694,7 +695,7 @@ SELECT LEASTSQUARES(field_name, start_val, step_val) FROM tb_name [WHERE clause]
### SPREAD
```sql
SELECT SPREAD(field_name) FROM { tb_name | stb_name } [WHERE clause];
SPREAD(expr)
```
**Description**: The difference between the max and the min of a specific column
......@@ -709,7 +710,7 @@ SELECT SPREAD(field_name) FROM { tb_name | stb_name } [WHERE clause];
### STDDEV
```sql
SELECT STDDEV(field_name) FROM tb_name [WHERE clause];
STDDEV(expr)
```
**Description**: Standard deviation of a specific column in a table or STable
......@@ -724,7 +725,7 @@ SELECT STDDEV(field_name) FROM tb_name [WHERE clause];
### SUM
```sql
SELECT SUM(field_name) FROM tb_name [WHERE clause];
SUM(expr)
```
**Description**: The sum of a specific column in a table or STable
......@@ -739,7 +740,7 @@ SELECT SUM(field_name) FROM tb_name [WHERE clause];
### HYPERLOGLOG
```sql
SELECT HYPERLOGLOG(field_name) FROM { tb_name | stb_name } [WHERE clause];
HYPERLOGLOG(expr)
```
**Description**:
......@@ -756,7 +757,7 @@ SELECT HYPERLOGLOG(field_name) FROM { tb_name | stb_name } [WHERE clause];
### HISTOGRAM
```sql
SELECT HISTOGRAM(field_name,bin_type, bin_description, normalized) FROM tb_name [WHERE clause];
HISTOGRAM(expr,bin_type, bin_description, normalized)
```
**Description**:Returns count of data points in user-specified ranges.
......@@ -786,7 +787,7 @@ SELECT HISTOGRAM(field_name,bin_type, bin_description, normalized) FROM tb_nam
### PERCENTILE
```sql
SELECT PERCENTILE(field_name, P) FROM { tb_name } [WHERE clause];
PERCENTILE(expr, p)
```
**Description**: The value whose rank in a specific column matches the specified percentage. If such a value matching the specified percentage doesn't exist in the column, an interpolation value will be returned.
......@@ -797,7 +798,7 @@ SELECT PERCENTILE(field_name, P) FROM { tb_name } [WHERE clause];
**Applicable table types**: table only
**More explanations**: _P_ is in range [0,100], when _P_ is 0, the result is same as using function MIN; when _P_ is 100, the result is same as function MAX.
**More explanations**: _p_ is in range [0,100], when _p_ is 0, the result is same as using function MIN; when _p_ is 100, the result is same as function MAX.
## Selection Functions
......@@ -807,7 +808,7 @@ Selection functions return one or more results depending. You can specify the ti
### BOTTOM
```sql
SELECT BOTTOM(field_name, K) FROM { tb_name | stb_name } [WHERE clause];
BOTTOM(expr, k)
```
**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.
......@@ -827,7 +828,7 @@ SELECT BOTTOM(field_name, K) FROM { tb_name | stb_name } [WHERE clause];
### FIRST
```sql
SELECT FIRST(field_name) FROM { tb_name | stb_name } [WHERE clause];
FIRST(expr)
```
**Description**: The first non-null value of a specific column in a table or STable
......@@ -847,7 +848,7 @@ SELECT FIRST(field_name) FROM { tb_name | stb_name } [WHERE clause];
### INTERP
```sql
SELECT INTERP(field_name) FROM { tb_name | stb_name } [WHERE where_condition] RANGE(timestamp1,timestamp2) EVERY(interval) FILL({ VALUE | PREV | NULL | LINEAR | NEXT});
INTERP(expr)
```
**Description**: The value that matches the specified timestamp range is returned, if existing; or an interpolation value is returned.
......@@ -870,7 +871,7 @@ SELECT INTERP(field_name) FROM { tb_name | stb_name } [WHERE where_condition] RA
### LAST
```sql
SELECT LAST(field_name) FROM { tb_name | stb_name } [WHERE clause];
LAST(expr)
```
**Description**: The last non-NULL value of a specific column in a table or STable
......@@ -891,7 +892,7 @@ SELECT LAST(field_name) FROM { tb_name | stb_name } [WHERE clause];
### LAST_ROW
```sql
SELECT LAST_ROW(field_name) FROM { tb_name | stb_name };
LAST_ROW(expr)
```
**Description**: The last row of a table or STable
......@@ -910,7 +911,7 @@ SELECT LAST_ROW(field_name) FROM { tb_name | stb_name };
### MAX
```sql
SELECT MAX(field_name) FROM { tb_name | stb_name } [WHERE clause];
MAX(expr)
```
**Description**: The maximum value of a specific column of a table or STable
......@@ -925,7 +926,7 @@ SELECT MAX(field_name) FROM { tb_name | stb_name } [WHERE clause];
### MIN
```sql
SELECT MIN(field_name) FROM {tb_name | stb_name} [WHERE clause];
MIN(expr)
```
**Description**: The minimum value of a specific column in a table or STable
......@@ -940,7 +941,7 @@ SELECT MIN(field_name) FROM {tb_name | stb_name} [WHERE clause];
### MODE
```sql
SELECT MODE(field_name) FROM tb_name [WHERE clause];
MODE(expr)
```
**Description**:The value which has the highest frequency of occurrence. NULL is returned if there are multiple values which have highest frequency of occurrence.
......@@ -955,7 +956,7 @@ SELECT MODE(field_name) FROM tb_name [WHERE clause];
### SAMPLE
```sql
SELECT SAMPLE(field_name, K) FROM { tb_name | stb_name } [WHERE clause]
SAMPLE(expr, k)
```
**Description**: _k_ sampling values of a specific column. The applicable range of _k_ is [1,1000].
......@@ -977,7 +978,7 @@ This function cannot be used in expression calculation.
### TAIL
```sql
SELECT TAIL(field_name, k, offset_val) FROM {tb_name | stb_name} [WHERE clause];
TAIL(expr, k, offset_val)
```
**Description**: The next _k_ rows are returned after skipping the last `offset_val` rows, NULL values are not ignored. `offset_val` is optional parameter. When it's not specified, the last _k_ rows are returned. When `offset_val` is used, the effect is same as `order by ts desc LIMIT k OFFSET offset_val`.
......@@ -994,7 +995,7 @@ SELECT TAIL(field_name, k, offset_val) FROM {tb_name | stb_name} [WHERE clause];
### TOP
```sql
SELECT TOP(field_name, K) FROM { tb_name | stb_name } [WHERE clause];
TOP(expr, k)
```
**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.
......@@ -1014,7 +1015,7 @@ SELECT TOP(field_name, K) FROM { tb_name | stb_name } [WHERE clause];
### UNIQUE
```sql
SELECT UNIQUE(field_name) FROM {tb_name | stb_name} [WHERE clause];
UNIQUE(expr)
```
**Description**: The values that occur the first time in the specified column. The effect is similar to `distinct` keyword, but it can also be used to match tags or timestamp. The first occurrence of a timestamp or tag is used.
......@@ -1033,7 +1034,7 @@ TDengine includes extensions to standard SQL that are intended specifically for
### CSUM
```sql
SELECT CSUM(field_name) FROM { tb_name | stb_name } [WHERE clause]
CSUM(expr)
```
**Description**: The cumulative sum of each row for a specific column. The number of output rows is same as that of the input rows.
......@@ -1056,7 +1057,12 @@ SELECT CSUM(field_name) FROM { tb_name | stb_name } [WHERE clause]
### DERIVATIVE
```sql
SELECT DERIVATIVE(field_name, time_interval, ignore_negative) FROM tb_name [WHERE clause];
DERIVATIVE(expr, time_inerval, ignore_negative)
ignore_negative: {
0
| 1
}
```
**Description**: The derivative of a specific column. The time rage can be specified by parameter `time_interval`, the minimum allowed time range is 1 second (1s); the value of `ignore_negative` can be 0 or 1, 1 means negative values are ignored.
......@@ -1075,7 +1081,12 @@ SELECT DERIVATIVE(field_name, time_interval, ignore_negative) FROM tb_name [WHER
### DIFF
```sql
SELECT {DIFF(field_name, ignore_negative) | DIFF(field_name)} FROM tb_name [WHERE clause];
DIFF(expr [, ignore_negative])
ignore_negative: {
0
| 1
}
```
**Description**: The different of each row with its previous row for a specific column. `ignore_negative` can be specified as 0 or 1, the default value is 1 if it's not specified. `1` means negative values are ignored.
......@@ -1095,7 +1106,7 @@ SELECT {DIFF(field_name, ignore_negative) | DIFF(field_name)} FROM tb_name [WHER
### IRATE
```sql
SELECT IRATE(field_name) FROM tb_name WHERE clause;
IRATE(expr)
```
**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.
......@@ -1110,7 +1121,7 @@ SELECT IRATE(field_name) FROM tb_name WHERE clause;
### MAVG
```sql
SELECT MAVG(field_name, K) FROM { tb_name | stb_name } [WHERE clause]
MAVG(expr, k)
```
**Description**: The moving average of continuous _k_ values of a specific column. If the number of input rows is less than _k_, nothing is returned. The applicable range of _k_ is [1,1000].
......@@ -1133,7 +1144,7 @@ SELECT MAVG(field_name, K) FROM { tb_name | stb_name } [WHERE clause]
### STATECOUNT
```sql
SELECT STATECOUNT(field_name, oper, val) FROM { tb_name | stb_name } [WHERE clause];
STATECOUNT(expr, oper, val)
```
**Description**: The number of continuous rows satisfying the specified conditions for a specific column. The result is shown as an extra column for each row. If the specified condition is evaluated as true, the number is increased by 1; otherwise the number is reset to -1. If the input value is NULL, then the corresponding row is skipped.
......@@ -1160,7 +1171,7 @@ SELECT STATECOUNT(field_name, oper, val) FROM { tb_name | stb_name } [WHERE clau
### STATEDURATION
```sql
SELECT stateDuration(field_name, oper, val, unit) FROM { tb_name | stb_name } [WHERE clause];
STATEDURATION(expr, oper, val, unit)
```
**Description**: The length of time range in which all rows satisfy the specified condition for a specific column. The result is shown as an extra column for each row. The length for the first row that satisfies the condition is 0. Next, if the condition is evaluated as true for a row, the time interval between current row and its previous row is added up to the time range; otherwise the time range length is reset to -1. If the value of the column is NULL, the corresponding row is skipped.
......@@ -1188,7 +1199,7 @@ SELECT stateDuration(field_name, oper, val, unit) FROM { tb_name | stb_name } [W
### TWA
```sql
SELECT TWA(field_name) FROM tb_name WHERE clause;
TWA(expr)
```
**Description**: Time weighted average on a specific column within a time range
......
......@@ -14,7 +14,7 @@ toc_max_heading_level: 4
#### ABS
```sql
SELECT ABS(field_name) FROM { tb_name | stb_name } [WHERE clause]
ABS(expr)
```
**功能说明**:获得指定字段的绝对值。
......@@ -32,7 +32,7 @@ SELECT ABS(field_name) FROM { tb_name | stb_name } [WHERE clause]
#### ACOS
```sql
SELECT ACOS(field_name) FROM { tb_name | stb_name } [WHERE clause]
ACOS(expr)
```
**功能说明**:获得指定字段的反余弦结果。
......@@ -50,7 +50,7 @@ SELECT ACOS(field_name) FROM { tb_name | stb_name } [WHERE clause]
#### ASIN
```sql
SELECT ASIN(field_name) FROM { tb_name | stb_name } [WHERE clause]
ASIN(expr)
```
**功能说明**:获得指定字段的反正弦结果。
......@@ -69,7 +69,7 @@ SELECT ASIN(field_name) FROM { tb_name | stb_name } [WHERE clause]
#### ATAN
```sql
SELECT ATAN(field_name) FROM { tb_name | stb_name } [WHERE clause]
ATAN(expr)
```
**功能说明**:获得指定字段的反正切结果。
......@@ -88,7 +88,7 @@ SELECT ATAN(field_name) FROM { tb_name | stb_name } [WHERE clause]
#### CEIL
```sql
SELECT CEIL(field_name) FROM { tb_name | stb_name } [WHERE clause];
CEIL(expr)
```
**功能说明**:获得指定字段的向上取整数的结果。
......@@ -106,7 +106,7 @@ SELECT CEIL(field_name) FROM { tb_name | stb_name } [WHERE clause];
#### COS
```sql
SELECT COS(field_name) FROM { tb_name | stb_name } [WHERE clause]
COS(expr)
```
**功能说明**:获得指定字段的余弦结果。
......@@ -124,7 +124,7 @@ SELECT COS(field_name) FROM { tb_name | stb_name } [WHERE clause]
#### FLOOR
```sql
SELECT FLOOR(field_name) FROM { tb_name | stb_name } [WHERE clause];
FLOOR(expr)
```
**功能说明**:获得指定字段的向下取整数的结果。
......@@ -133,10 +133,10 @@ SELECT FLOOR(field_name) FROM { tb_name | stb_name } [WHERE clause];
#### LOG
```sql
SELECT LOG(field_name[, base]) FROM { tb_name | stb_name } [WHERE clause]
LOG(expr1[, expr2])
```
**功能说明**:获得指定字段对于底数 base 的对数。如果 base 参数省略,则返回指定字段的自然对数值。
**功能说明**:获得 expr1 对于底数 expr2 的对数。如果 expr2 参数省略,则返回指定字段的自然对数值。
**返回结果类型**:DOUBLE。
......@@ -152,10 +152,10 @@ SELECT LOG(field_name[, base]) FROM { tb_name | stb_name } [WHERE clause]
#### POW
```sql
SELECT POW(field_name, power) FROM { tb_name | stb_name } [WHERE clause]
POW(expr1, expr2)
```
**功能说明**:获得指定字段的指数为 power 的幂。
**功能说明**:获得 expr1 的指数为 expr2 的幂。
**返回结果类型**:DOUBLE。
......@@ -171,7 +171,7 @@ SELECT POW(field_name, power) FROM { tb_name | stb_name } [WHERE clause]
#### ROUND
```sql
SELECT ROUND(field_name) FROM { tb_name | stb_name } [WHERE clause];
ROUND(expr)
```
**功能说明**:获得指定字段的四舍五入的结果。
......@@ -181,7 +181,7 @@ SELECT ROUND(field_name) FROM { tb_name | stb_name } [WHERE clause];
#### SIN
```sql
SELECT SIN(field_name) FROM { tb_name | stb_name } [WHERE clause]
SIN(expr)
```
**功能说明**:获得指定字段的正弦结果。
......@@ -199,7 +199,7 @@ SELECT SIN(field_name) FROM { tb_name | stb_name } [WHERE clause]
#### SQRT
```sql
SELECT SQRT(field_name) FROM { tb_name | stb_name } [WHERE clause]
SQRT(expr)
```
**功能说明**:获得指定字段的平方根。
......@@ -217,7 +217,7 @@ SELECT SQRT(field_name) FROM { tb_name | stb_name } [WHERE clause]
#### TAN
```sql
SELECT TAN(field_name) FROM { tb_name | stb_name } [WHERE clause]
TAN(expr)
```
**功能说明**:获得指定字段的正切结果。
......@@ -239,7 +239,7 @@ SELECT TAN(field_name) FROM { tb_name | stb_name } [WHERE clause]
#### CHAR_LENGTH
```sql
SELECT CHAR_LENGTH(str|column) FROM { tb_name | stb_name } [WHERE clause]
CHAR_LENGTH(expr)
```
**功能说明**:以字符计数的字符串长度。
......@@ -255,7 +255,7 @@ SELECT CHAR_LENGTH(str|column) FROM { tb_name | stb_name } [WHERE clause]
#### CONCAT
```sql
SELECT CONCAT(str1|column1, str2|column2, ...) FROM { tb_name | stb_name } [WHERE clause]
CONCAT(expr1, expr2 [, expr] ... )
```
**功能说明**:字符串连接函数。
......@@ -272,7 +272,7 @@ SELECT CONCAT(str1|column1, str2|column2, ...) FROM { tb_name | stb_name } [WHER
#### CONCAT_WS
```sql
SELECT CONCAT_WS(separator, str1|column1, str2|column2, ...) FROM { tb_name | stb_name } [WHERE clause]
CONCAT_WS(separator_expr, expr1, expr2 [, expr] ...)
```
**功能说明**:带分隔符的字符串连接函数。
......@@ -289,7 +289,7 @@ SELECT CONCAT_WS(separator, str1|column1, str2|column2, ...) FROM { tb_name | st
#### LENGTH
```sql
SELECT LENGTH(str|column) FROM { tb_name | stb_name } [WHERE clause]
LENGTH(expr)
```
**功能说明**:以字节计数的字符串长度。
......@@ -306,7 +306,7 @@ SELECT LENGTH(str|column) FROM { tb_name | stb_name } [WHERE clause]
#### LOWER
```sql
SELECT LOWER(str|column) FROM { tb_name | stb_name } [WHERE clause]
LOWER(expr)
```
**功能说明**:将字符串参数值转换为全小写字母。
......@@ -323,7 +323,7 @@ SELECT LOWER(str|column) FROM { tb_name | stb_name } [WHERE clause]
#### LTRIM
```sql
SELECT LTRIM(str|column) FROM { tb_name | stb_name } [WHERE clause]
LTRIM(expr)
```
**功能说明**:返回清除左边空格后的字符串。
......@@ -340,7 +340,7 @@ SELECT LTRIM(str|column) FROM { tb_name | stb_name } [WHERE clause]
#### RTRIM
```sql
SELECT LTRIM(str|column) FROM { tb_name | stb_name } [WHERE clause]
LTRIM(expr)
```
**功能说明**:返回清除右边空格后的字符串。
......@@ -357,7 +357,7 @@ SELECT LTRIM(str|column) FROM { tb_name | stb_name } [WHERE clause]
#### SUBSTR
```sql
SELECT SUBSTR(str,pos[,len]) FROM { tb_name | stb_name } [WHERE clause]
SUBSTR(expr, pos [,len])
```
**功能说明**:从源字符串 str 中的指定位置 pos 开始取一个长度为 len 的子串并返回。如果输入参数 len 被忽略,返回的子串包含从 pos 开始的整个字串。
......@@ -374,7 +374,7 @@ SELECT SUBSTR(str,pos[,len]) FROM { tb_name | stb_name } [WHERE clause]
#### UPPER
```sql
SELECT UPPER(str|column) FROM { tb_name | stb_name } [WHERE clause]
UPPER(expr)
```
**功能说明**:将字符串参数值转换为全大写字母。
......@@ -395,10 +395,10 @@ SELECT UPPER(str|column) FROM { tb_name | stb_name } [WHERE clause]
#### CAST
```sql
SELECT CAST(expression AS type_name) FROM { tb_name | stb_name } [WHERE clause]
CAST(expr AS type_name)
```
**功能说明**:数据类型转换函数,返回 expression 转换为 type_name 指定的类型后的结果。只适用于 select 子句中。
**功能说明**:数据类型转换函数,返回 expr 转换为 type_name 指定的类型后的结果。只适用于 select 子句中。
**返回结果类型**:CAST 中指定的类型(type_name)。
......@@ -419,7 +419,7 @@ SELECT CAST(expression AS type_name) FROM { tb_name | stb_name } [WHERE clause]
#### TO_ISO8601
```sql
SELECT TO_ISO8601(ts[, timezone]) FROM { tb_name | stb_name } [WHERE clause];
TO_ISO8601(expr [, timezone])
```
**功能说明**:将 UNIX 时间戳转换成为 ISO8601 标准的日期时间格式,并附加时区信息。timezone 参数允许用户为输出结果指定附带任意时区信息。如果 timezone 参数省略,输出结果则附带当前客户端的系统时区信息。
......@@ -442,7 +442,7 @@ SELECT TO_ISO8601(ts[, timezone]) FROM { tb_name | stb_name } [WHERE clause];
#### TO_JSON
```sql
SELECT TO_JSON(str_literal) FROM { tb_name | stb_name } [WHERE clause];
TO_JSON(str_literal)
```
**功能说明**: 将字符串常量转换为 JSON 类型。
......@@ -459,7 +459,7 @@ SELECT TO_JSON(str_literal) FROM { tb_name | stb_name } [WHERE clause];
#### TO_UNIXTIMESTAMP
```sql
SELECT TO_UNIXTIMESTAMP(datetime_string) FROM { tb_name | stb_name } [WHERE clause];
TO_UNIXTIMESTAMP(expr)
```
**功能说明**:将日期时间格式的字符串转换成为 UNIX 时间戳。
......@@ -487,9 +487,7 @@ SELECT TO_UNIXTIMESTAMP(datetime_string) FROM { tb_name | stb_name } [WHERE clau
#### NOW
```sql
SELECT NOW() FROM { tb_name | stb_name } [WHERE clause];
SELECT select_expr FROM { tb_name | stb_name } WHERE ts_col cond_operatior NOW();
INSERT INTO tb_name VALUES (NOW(), ...);
NOW()
```
**功能说明**:返回客户端当前系统时间。
......@@ -512,7 +510,7 @@ INSERT INTO tb_name VALUES (NOW(), ...);
#### TIMEDIFF
```sql
SELECT TIMEDIFF(ts | datetime_string1, ts | datetime_string2 [, time_unit]) FROM { tb_name | stb_name } [WHERE clause];
TIMEDIFF(expr1, expr2 [, time_unit])
```
**功能说明**:计算两个时间戳之间的差值,并近似到时间单位 time_unit 指定的精度。
......@@ -535,7 +533,7 @@ SELECT TIMEDIFF(ts | datetime_string1, ts | datetime_string2 [, time_unit]) FROM
#### TIMETRUNCATE
```sql
SELECT TIMETRUNCATE(ts | datetime_string , time_unit) FROM { tb_name | stb_name } [WHERE clause];
TIMETRUNCATE(expr, time_unit)
```
**功能说明**:将时间戳按照指定时间单位 time_unit 进行截断。
......@@ -556,7 +554,7 @@ SELECT TIMETRUNCATE(ts | datetime_string , time_unit) FROM { tb_name | stb_name
#### TIMEZONE
```sql
SELECT TIMEZONE() FROM { tb_name | stb_name } [WHERE clause];
TIMEZONE()
```
**功能说明**:返回客户端当前时区信息。
......@@ -571,9 +569,7 @@ SELECT TIMEZONE() FROM { tb_name | stb_name } [WHERE clause];
#### TODAY
```sql
SELECT TODAY() FROM { tb_name | stb_name } [WHERE clause];
SELECT select_expr FROM { tb_name | stb_name } WHERE ts_col cond_operatior TODAY()];
INSERT INTO tb_name VALUES (TODAY(), ...);
TODAY()
```
**功能说明**:返回客户端当日零时的系统时间。
......@@ -600,7 +596,12 @@ TDengine 支持针对数据的聚合查询。提供如下聚合函数。
### APERCENTILE
```sql
SELECT APERCENTILE(field_name, P[, algo_type]) FROM { tb_name | stb_name } [WHERE clause]
APERCENTILE(expr, p [, algo_type])
algo_type: {
"default"
| "t-digest"
}
```
**功能说明**:统计表/超级表中指定列的值的近似百分比分位数,与 PERCENTILE 函数相似,但是返回近似结果。
......@@ -612,14 +613,14 @@ SELECT APERCENTILE(field_name, P[, algo_type]) FROM { tb_name | stb_name } [WHER
**适用于**:表和超级表。
**说明**
- P值范围是[0,100],当为0时等同于MIN,为100时等同于MAX。
- p值范围是[0,100],当为0时等同于MIN,为100时等同于MAX。
- algo_type 取值为 "default" 或 "t-digest"。 输入为 "default" 时函数使用基于直方图算法进行计算。输入为 "t-digest" 时使用t-digest算法计算分位数的近似结果。如果不指定 algo_type 则使用 "default" 算法。
- "t-digest"算法的近似结果对于输入数据顺序敏感,对超级表查询时不同的输入排序结果可能会有微小的误差。
### AVG
```sql
SELECT AVG(field_name) FROM tb_name [WHERE clause];
AVG(expr)
```
**功能说明**:统计指定字段的平均值。
......@@ -634,7 +635,7 @@ SELECT AVG(field_name) FROM tb_name [WHERE clause];
### COUNT
```sql
SELECT COUNT([*|field_name]) FROM tb_name [WHERE clause];
COUNT({* | expr})
```
**功能说明**:统计指定字段的记录行数。
......@@ -654,7 +655,7 @@ SELECT COUNT([*|field_name]) FROM tb_name [WHERE clause];
### ELAPSED
```sql
SELECT ELAPSED(ts_primary_key [, time_unit]) FROM { tb_name | stb_name } [WHERE clause] [INTERVAL(interval [, offset]) [SLIDING sliding]];
ELAPSED(ts_primary_key [, time_unit])
```
**功能说明**:elapsed函数表达了统计周期内连续的时间长度,和twa函数配合使用可以计算统计曲线下的面积。在通过INTERVAL子句指定窗口的情况下,统计在给定时间范围内的每个窗口内有数据覆盖的时间范围;如果没有INTERVAL子句,则返回整个给定时间范围内的有数据覆盖的时间范围。注意,ELAPSED返回的并不是时间范围的绝对值,而是绝对值除以time_unit所得到的单位个数。
......@@ -666,7 +667,7 @@ SELECT ELAPSED(ts_primary_key [, time_unit]) FROM { tb_name | stb_name } [WHERE
**适用于**: 表,超级表,嵌套查询的外层查询
**说明**
- field_name参数只能是表的第一列,即 TIMESTAMP 类型的主键列。
- ts_primary_key参数只能是表的第一列,即 TIMESTAMP 类型的主键列。
- 按time_unit参数指定的时间单位返回,最小是数据库的时间分辨率。time_unit 参数未指定时,以数据库的时间分辨率为时间单位。支持的时间单位 time_unit 如下:
1b(纳秒), 1u(微秒),1a(毫秒),1s(秒),1m(分),1h(小时),1d(天), 1w(周)。
- 可以和interval组合使用,返回每个时间窗口的时间戳差值。需要特别注意的是,除第一个时间窗口和最后一个时间窗口外,中间窗口的时间戳差值均为窗口长度。
......@@ -680,14 +681,14 @@ SELECT ELAPSED(ts_primary_key [, time_unit]) FROM { tb_name | stb_name } [WHERE
### LEASTSQUARES
```sql
SELECT LEASTSQUARES(field_name, start_val, step_val) FROM tb_name [WHERE clause];
LEASTSQUARES(expr, start_val, step_val)
```
**功能说明**:统计表中某列的值是主键(时间戳)的拟合直线方程。start_val 是自变量初始值,step_val 是自变量的步长值。
**返回数据类型**:字符串表达式(斜率, 截距)。
**适用数据类型**field_name 必须是数值类型。
**适用数据类型**expr 必须是数值类型。
**适用于**:表。
......@@ -695,7 +696,7 @@ SELECT LEASTSQUARES(field_name, start_val, step_val) FROM tb_name [WHERE clause]
### SPREAD
```sql
SELECT SPREAD(field_name) FROM { tb_name | stb_name } [WHERE clause];
SPREAD(expr)
```
**功能说明**:统计表中某列的最大值和最小值之差。
......@@ -710,7 +711,7 @@ SELECT SPREAD(field_name) FROM { tb_name | stb_name } [WHERE clause];
### STDDEV
```sql
SELECT STDDEV(field_name) FROM tb_name [WHERE clause];
STDDEV(expr)
```
**功能说明**:统计表中某列的均方差。
......@@ -725,7 +726,7 @@ SELECT STDDEV(field_name) FROM tb_name [WHERE clause];
### SUM
```sql
SELECT SUM(field_name) FROM tb_name [WHERE clause];
SUM(expr)
```
**功能说明**:统计表/超级表中某列的和。
......@@ -740,7 +741,7 @@ SELECT SUM(field_name) FROM tb_name [WHERE clause];
### HYPERLOGLOG
```sql
SELECT HYPERLOGLOG(field_name) FROM { tb_name | stb_name } [WHERE clause];
HYPERLOGLOG(expr)
```
**功能说明**
......@@ -757,7 +758,7 @@ SELECT HYPERLOGLOG(field_name) FROM { tb_name | stb_name } [WHERE clause];
### HISTOGRAM
```sql
SELECT HISTOGRAM(field_namebin_type, bin_description, normalized) FROM tb_name [WHERE clause];
HISTOGRAM(exprbin_type, bin_description, normalized)
```
**功能说明**:统计数据按照用户指定区间的分布。
......@@ -787,7 +788,7 @@ SELECT HISTOGRAM(field_name,bin_type, bin_description, normalized) FROM tb_nam
### PERCENTILE
```sql
SELECT PERCENTILE(field_name, P) FROM { tb_name } [WHERE clause];
PERCENTILE(expr, p)
```
**功能说明**:统计表中某列的值百分比分位数。
......@@ -808,7 +809,7 @@ SELECT PERCENTILE(field_name, P) FROM { tb_name } [WHERE clause];
### BOTTOM
```sql
SELECT BOTTOM(field_name, K) FROM { tb_name | stb_name } [WHERE clause];
BOTTOM(expr, k)
```
**功能说明**:统计表/超级表中某列的值最小 _k_ 个非 NULL 值。如果多条数据取值一样,全部取用又会超出 k 条限制时,系统会从相同值中随机选取符合要求的数量返回。
......@@ -828,7 +829,7 @@ SELECT BOTTOM(field_name, K) FROM { tb_name | stb_name } [WHERE clause];
### FIRST
```sql
SELECT FIRST(field_name) FROM { tb_name | stb_name } [WHERE clause];
FIRST(expr)
```
**功能说明**:统计表/超级表中某列的值最先写入的非 NULL 值。
......@@ -848,7 +849,7 @@ SELECT FIRST(field_name) FROM { tb_name | stb_name } [WHERE clause];
### INTERP
```sql
SELECT INTERP(field_name) FROM { tb_name | stb_name } [WHERE where_condition] RANGE(timestamp1,timestamp2) EVERY(interval) FILL({ VALUE | PREV | NULL | LINEAR | NEXT});
INTERP(expr)
```
**功能说明**:返回指定时间截面指定列的记录值或插值。
......@@ -871,7 +872,7 @@ SELECT INTERP(field_name) FROM { tb_name | stb_name } [WHERE where_condition] RA
### LAST
```sql
SELECT LAST(field_name) FROM { tb_name | stb_name } [WHERE clause];
LAST(expr)
```
**功能说明**:统计表/超级表中某列的值最后写入的非 NULL 值。
......@@ -892,7 +893,7 @@ SELECT LAST(field_name) FROM { tb_name | stb_name } [WHERE clause];
### LAST_ROW
```sql
SELECT LAST_ROW(field_name) FROM { tb_name | stb_name };
LAST_ROW(expr)
```
**功能说明**:返回表/超级表的最后一条记录。
......@@ -911,7 +912,7 @@ SELECT LAST_ROW(field_name) FROM { tb_name | stb_name };
### MAX
```sql
SELECT MAX(field_name) FROM { tb_name | stb_name } [WHERE clause];
MAX(expr)
```
**功能说明**:统计表/超级表中某列的值最大值。
......@@ -926,7 +927,7 @@ SELECT MAX(field_name) FROM { tb_name | stb_name } [WHERE clause];
### MIN
```sql
SELECT MIN(field_name) FROM {tb_name | stb_name} [WHERE clause];
MIN(expr)
```
**功能说明**:统计表/超级表中某列的值最小值。
......@@ -941,7 +942,7 @@ SELECT MIN(field_name) FROM {tb_name | stb_name} [WHERE clause];
### MODE
```sql
SELECT MODE(field_name) FROM tb_name [WHERE clause];
MODE(expr)
```
**功能说明**:返回出现频率最高的值,若存在多个频率相同的最高值,输出NULL。
......@@ -956,7 +957,7 @@ SELECT MODE(field_name) FROM tb_name [WHERE clause];
### SAMPLE
```sql
SELECT SAMPLE(field_name, K) FROM { tb_name | stb_name } [WHERE clause]
SAMPLE(expr, k)
```
**功能说明**: 获取数据的 k 个采样值。参数 k 的合法输入范围是 1≤ k ≤ 1000。
......@@ -978,7 +979,7 @@ SELECT SAMPLE(field_name, K) FROM { tb_name | stb_name } [WHERE clause]
### TAIL
```sql
SELECT TAIL(field_name, k, offset_val) FROM {tb_name | stb_name} [WHERE clause];
TAIL(expr, k [, offset_rows])
```
**功能说明**:返回跳过最后 offset_val 个,然后取连续 k 个记录,不忽略 NULL 值。offset_val 可以不输入。此时返回最后的 k 个记录。当有 offset_val 输入的情况下,该函数功能等效于 `order by ts desc LIMIT k OFFSET offset_val`
......@@ -995,7 +996,7 @@ SELECT TAIL(field_name, k, offset_val) FROM {tb_name | stb_name} [WHERE clause];
### TOP
```sql
SELECT TOP(field_name, K) FROM { tb_name | stb_name } [WHERE clause];
TOP(expr, k)
```
**功能说明**: 统计表/超级表中某列的值最大 _k_ 个非 NULL 值。如果多条数据取值一样,全部取用又会超出 k 条限制时,系统会从相同值中随机选取符合要求的数量返回。
......@@ -1015,7 +1016,7 @@ SELECT TOP(field_name, K) FROM { tb_name | stb_name } [WHERE clause];
### UNIQUE
```sql
SELECT UNIQUE(field_name) FROM {tb_name | stb_name} [WHERE clause];
UNIQUE(expr)
```
**功能说明**:返回该列的数值首次出现的值。该函数功能与 distinct 相似,但是可以匹配标签和时间戳信息。可以针对除时间列以外的字段进行查询,可以匹配标签和时间戳,其中的标签和时间戳是第一次出现时刻的标签和时间戳。
......@@ -1034,7 +1035,7 @@ SELECT UNIQUE(field_name) FROM {tb_name | stb_name} [WHERE clause];
### CSUM
```sql
SELECT CSUM(field_name) FROM { tb_name | stb_name } [WHERE clause]
CSUM(expr)
```
**功能说明**:累加和(Cumulative sum),输出行与输入行数相同。
......@@ -1057,7 +1058,12 @@ SELECT CSUM(field_name) FROM { tb_name | stb_name } [WHERE clause]
### DERIVATIVE
```sql
SELECT DERIVATIVE(field_name, time_interval, ignore_negative) FROM tb_name [WHERE clause];
DERIVATIVE(expr, time_interval, ignore_negative)
ignore_negative: {
0
| 1
}
```
**功能说明**:统计表中某列数值的单位变化率。其中单位时间区间的长度可以通过 time_interval 参数指定,最小可以是 1 秒(1s);ignore_negative 参数的值可以是 0 或 1,为 1 时表示忽略负值。
......@@ -1076,7 +1082,12 @@ SELECT DERIVATIVE(field_name, time_interval, ignore_negative) FROM tb_name [WHER
### DIFF
```sql
SELECT {DIFF(field_name, ignore_negative) | DIFF(field_name)} FROM tb_name [WHERE clause];
DIFF(expr [, ignore_negative])
ignore_negative: {
0
| 1
}
```
**功能说明**:统计表中某列的值与前一行对应值的差。 ignore_negative 取值为 0|1 , 可以不填,默认值为 0. 不忽略负值。ignore_negative 为 1 时表示忽略负数。
......@@ -1096,7 +1107,7 @@ SELECT {DIFF(field_name, ignore_negative) | DIFF(field_name)} FROM tb_name [WHER
### IRATE
```sql
SELECT IRATE(field_name) FROM tb_name WHERE clause;
IRATE(expr)
```
**功能说明**:计算瞬时增长率。使用时间区间中最后两个样本数据来计算瞬时增长速率;如果这两个值呈递减关系,那么只取最后一个数用于计算,而不是使用二者差值。
......@@ -1111,7 +1122,7 @@ SELECT IRATE(field_name) FROM tb_name WHERE clause;
### MAVG
```sql
SELECT MAVG(field_name, K) FROM { tb_name | stb_name } [WHERE clause]
MAVG(expr, k)
```
**功能说明**: 计算连续 k 个值的移动平均数(moving average)。如果输入行数小于 k,则无结果输出。参数 k 的合法输入范围是 1≤ k ≤ 1000。
......@@ -1134,7 +1145,7 @@ SELECT MAVG(field_name, K) FROM { tb_name | stb_name } [WHERE clause]
### STATECOUNT
```sql
SELECT STATECOUNT(field_name, oper, val) FROM { tb_name | stb_name } [WHERE clause];
STATECOUNT(expr, oper, val)
```
**功能说明**:返回满足某个条件的连续记录的个数,结果作为新的一列追加在每行后面。条件根据参数计算,如果条件为 true 则加 1,条件为 false 则重置为-1,如果数据为 NULL,跳过该条数据。
......@@ -1161,7 +1172,7 @@ SELECT STATECOUNT(field_name, oper, val) FROM { tb_name | stb_name } [WHERE clau
### STATEDURATION
```sql
SELECT stateDuration(field_name, oper, val, unit) FROM { tb_name | stb_name } [WHERE clause];
STATEDURATION(expr, oper, val, unit)
```
**功能说明**:返回满足某个条件的连续记录的时间长度,结果作为新的一列追加在每行后面。条件根据参数计算,如果条件为 true 则加上两个记录之间的时间长度(第一个满足条件的记录时间长度记为 0),条件为 false 则重置为-1,如果数据为 NULL,跳过该条数据。
......@@ -1189,7 +1200,7 @@ SELECT stateDuration(field_name, oper, val, unit) FROM { tb_name | stb_name } [W
### TWA
```sql
SELECT TWA(field_name) FROM tb_name WHERE clause;
TWA(expr)
```
**功能说明**:时间加权平均函数。统计表中某列在一段时间内的时间加权平均。
......
......@@ -221,14 +221,15 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
return terrno;
}
SSdbRow *pOldRow = *ppOldRow;
pOldRow->status = pRaw->status;
atomic_add_fetch_32(&pOldRow->refCount, 1);
sdbPrintOper(pSdb, pOldRow, "delete");
taosHashRemove(hash, pOldRow->pObj, keySize);
pSdb->tableVer[pOldRow->type]++;
taosThreadRwlockUnlock(pLock);
pSdb->tableVer[pOldRow->type]++;
sdbFreeRow(pSdb, pRow, false);
sdbCheckRow(pSdb, pOldRow);
......@@ -317,7 +318,7 @@ static void sdbCheckRow(SSdb *pSdb, SSdbRow *pRow) {
TdThreadRwlock *pLock = &pSdb->locks[pRow->type];
taosThreadRwlockWrlock(pLock);
int32_t ref = atomic_load_32(&pRow->refCount);
int32_t ref = atomic_sub_fetch_32(&pRow->refCount, 1);
sdbPrintOper(pSdb, pRow, "check");
if (ref <= 0 && pRow->status == SDB_STATUS_DROPPED) {
sdbFreeRow(pSdb, pRow, true);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册