commit
01ab229c66
|
@ -1209,27 +1209,40 @@ ignore_negative: {
|
|||
### DIFF
|
||||
|
||||
```sql
|
||||
DIFF(expr [, ignore_negative])
|
||||
DIFF(expr [, ignore_option])
|
||||
|
||||
ignore_negative: {
|
||||
ignore_option: {
|
||||
0
|
||||
| 1
|
||||
| 2
|
||||
| 3
|
||||
}
|
||||
```
|
||||
|
||||
**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. For tables with composite primary key, the data with the smallest primary key value is used to calculate the difference.
|
||||
**Description**: The difference of each row with its previous row for a specific column. `ignore_option` takes the value of 0|1|2|3, the default value is 0 if it's not specified.
|
||||
- `0` means that negative values (diff results) are not ignored and null values are not ignored
|
||||
- `1` means that negative values (diff results) are treated as null values
|
||||
- `2` means that negative values (diff results) are not ignored but null values are ignored
|
||||
- `3` means that negative values (diff results) are ignored and null values are ignored
|
||||
- For tables with composite primary key, the data with the smallest primary key value is used to calculate the difference.
|
||||
|
||||
**Return value type**:Same as the data type of the column being operated upon
|
||||
**Return value type**: `bool`, `timestamp` and `integer` value type all return `int_64`, `float` type returns `double`; if the diff result overflows, it is returned as overflow.
|
||||
|
||||
**Applicable data types**: Numeric
|
||||
**Applicable data types**: Numeric type, timestamp and bool type.
|
||||
|
||||
**Applicable table types**: standard tables and supertables
|
||||
|
||||
**More explanation**:
|
||||
|
||||
- The number of result rows is the number of rows subtracted by one, no output for the first row
|
||||
- It can be used together with a selected column. For example: select \_rowts, DIFF() from.
|
||||
|
||||
- diff is to calculate the difference of a specific column in current row and the **first valid data before the row**. The **first valid data before the row** refers to the most adjacent non-null value of same column with smaller timestamp.
|
||||
- The diff result of numeric type is the corresponding arithmatic difference; the timestamp is calculated based on the timestamp precision of the database; when calculating diff, `true` is treated as 1 and `false` is treated as 0
|
||||
- If the data of current row is NULL or can't find the **first valid data before the current row**, the diff result is NULL
|
||||
- When ignoring negative values (ignore_option is set to 1 or 3), if the diff result is negative, the result is set to null, and then filtered according to the null value filtering rule
|
||||
- When the diff result has an overflow, whether to ignore the negative value depends on the result of the logical operation is positive or negative. For example, the value of 9223372036854775800 - (-9223372036854775806) exceeds the range of BIGINT, and the diff result will display the overflow value -10, but it will not be ignored as a negative value
|
||||
- Single or multiple diffs can be used in a single statement, and for each diff you can specify same or different `ignore_option`. When there are multiple diffs in a single statement, when and only when all the diff results are NULL for a row and each diff's `ignore_option` is specified as ignoring NULL, the output of this row will be removed from the result set.
|
||||
- Can be used with the selected associated columns. For example: `select _rowts, DIFF()`.
|
||||
- When there is not composite primary key, if there are the same timestamps across different subtables, it will prompt "Duplicate timestamps not allowed"
|
||||
- When using with composite primary key, there may be same combination of timestamp and complete primary key across sub-tables, which row will be used depends on which row is found first, that means the result of running diff() multiple times may be different in such a case
|
||||
|
||||
### IRATE
|
||||
|
||||
|
|
|
@ -1200,27 +1200,40 @@ ignore_negative: {
|
|||
### DIFF
|
||||
|
||||
```sql
|
||||
DIFF(expr [, ignore_negative])
|
||||
DIFF(expr [, ignore_option])
|
||||
|
||||
ignore_negative: {
|
||||
ignore_option: {
|
||||
0
|
||||
| 1
|
||||
| 2
|
||||
| 3
|
||||
}
|
||||
```
|
||||
|
||||
**功能说明**:统计表中某列的值与前一行对应值的差。 ignore_negative 取值为 0|1 , 可以不填,默认值为 0. 不忽略负值。ignore_negative 为 1 时表示忽略负数。对于你存在复合主键的表的查询,若时间戳相同的数据存在多条,则只有对应的复合主键最小的数据参与运算。
|
||||
**功能说明**:统计表中特定列与之前行的当前列有效值之差。 ignore_option 取值为 0|1|2|3 , 可以不填,默认值为 0.
|
||||
- `0` 表示不忽略(diff结果)负值不忽略 null 值
|
||||
- `1` 表示(diff结果)负值作为 null 值
|
||||
- `2` 表示不忽略(diff结果)负值但忽略 null 值
|
||||
- `3` 表示忽略(diff结果)负值且忽略 null 值
|
||||
- 对于存在复合主键的表的查询,若时间戳相同的数据存在多条,则只有对应的复合主键最小的数据参与运算。
|
||||
|
||||
**返回数据类型**:同应用字段。
|
||||
**返回数据类型**:bool、时间戳及整型数值类型均返回 int_64,浮点类型返回 double, 若 diff 结果溢出则返回溢出后的值。
|
||||
|
||||
**适用数据类型**:数值类型。
|
||||
**适用数据类型**:数值类型、时间戳和 bool 类型。
|
||||
|
||||
**适用于**:表和超级表。
|
||||
|
||||
**使用说明**:
|
||||
|
||||
- 输出结果行数是范围内总行数减一,第一行没有结果输出。
|
||||
- 可以与选择相关联的列一起使用。 例如: select \_rowts, DIFF() from。
|
||||
|
||||
- diff 是计算本行特定列与同列的前一个有效数据的差值,同列的前一个有效数据:指的是同一列中时间戳较小的最临近的非空值。
|
||||
- 数值类型 diff 结果为对应的算术差值;时间戳类型根据数据库的时间戳精度进行差值计算;bool 类型计算差值时 true 视为 1, false 视为 0
|
||||
- 如当前行数据为 null 或者没有找到同列前一个有效数据时,diff 结果为 null
|
||||
- 忽略负值时( ignore_option 设置为 1 或 3 ),如果 diff 结果为负值,则结果设置为 null,然后根据 null 值过滤规则进行过滤
|
||||
- 当 diff 结果发生溢出时,结果是否是`应该忽略的负值`取决于逻辑运算结果是正数还是负数,例如 9223372036854775800 - (-9223372036854775806) 的值超出 BIGINT 的范围 ,diff 结果会显示溢出值 -10,但并不会被作为负值忽略
|
||||
- 单个语句中可以使用单个或者多个 diff,并且每个 diff 可以指定相同或不同的 ignore_option ,当单个语句中存在多个 diff 时当且仅当某行所有 diff 的结果都为 null ,并且 ignore_option 都设置为忽略 null 值,该行才从结果集中剔除
|
||||
- 可以选择与相关联的列一起使用。 例如: select _rowts, DIFF() from。
|
||||
- 当没有复合主键时,如果不同的子表有相同时间戳的数据,会提示 "Duplicate timestamps not allowed"
|
||||
- 当使用复合主键时,不同子表的时间戳和主键组合可能相同,使用哪一行取决于先找到哪一行,这意味着在这种情况下多次运行 diff() 的结果可能会不同。
|
||||
|
||||
### IRATE
|
||||
|
||||
|
|
Loading…
Reference in New Issue