fix: add partition by examples

This commit is contained in:
dapan1121 2023-12-11 15:39:40 +08:00
parent fceaedce22
commit e77ae68cbd
2 changed files with 18 additions and 4 deletions

View File

@ -16,7 +16,10 @@ When you query a supertable, you may need to partition the supertable by some di
PARTITION BY part_list PARTITION BY part_list
``` ```
part_list can be any scalar expression, such as a column, constant, scalar function, or a combination of the preceding items. part_list can be any scalar expression, such as a column, constant, scalar function, or a combination of the preceding items. For example, grouping data by label location, taking the average voltage within each group.
```sql
select avg(voltage) from meters partition by location
```
A PARTITION BY clause is processed as follows: A PARTITION BY clause is processed as follows:
@ -28,7 +31,10 @@ A PARTITION BY clause is processed as follows:
select max(current) from meters partition by location interval(10m) select max(current) from meters partition by location interval(10m)
``` ```
The most common usage of PARTITION BY is partitioning the data in subtables by tags then perform computation when querying data in a supertable. More specifically, `PARTITION BY TBNAME` partitions the data of each subtable into a single timeline, and this method facilitates the statistical analysis in many use cases of processing timeseries data. The most common usage of PARTITION BY is partitioning the data in subtables by tags then perform computation when querying data in a supertable. More specifically, `PARTITION BY TBNAME` partitions the data of each subtable into a single timeline, and this method facilitates the statistical analysis in many use cases of processing timeseries data. For example, calculate the average voltage of each meter every 10 minutes£º
```sql
select avg(voltage) from meters partition by tbname interval(10m)
```
## Windowed Queries ## Windowed Queries

View File

@ -16,7 +16,11 @@ TDengine 提供的特色查询包括数据切分查询和时间窗口切分查
PARTITION BY part_list PARTITION BY part_list
``` ```
part_list 可以是任意的标量表达式,包括列、常量、标量函数和它们的组合。 part_list 可以是任意的标量表达式,包括列、常量、标量函数和它们的组合。例如,将数据按标签 location 进行分组,取每个分组内的电压平均值:
```sql
select avg(voltage) from meters partition by location
```
TDengine 按如下方式处理数据切分子句: TDengine 按如下方式处理数据切分子句:
@ -27,7 +31,11 @@ TDengine 按如下方式处理数据切分子句:
```sql ```sql
select max(current) from meters partition by location interval(10m) select max(current) from meters partition by location interval(10m)
``` ```
数据切分子句最常见的用法就是在超级表查询中,按标签将子表数据进行切分,然后分别进行计算。特别是 PARTITION BY TBNAME 用法,它将每个子表的数据独立出来,形成一条条独立的时间序列,极大的方便了各种时序场景的统计分析。 数据切分子句最常见的用法就是在超级表查询中,按标签将子表数据进行切分,然后分别进行计算。特别是 PARTITION BY TBNAME 用法,它将每个子表的数据独立出来,形成一条条独立的时间序列,极大的方便了各种时序场景的统计分析。例如,统计每个电表每 10 分钟内的电压平均值:
```sql
select avg(voltage) from meters partition by tbname interval(10m)
```
## 窗口切分查询 ## 窗口切分查询