fix: optimize sample sql

This commit is contained in:
dapan1121 2023-12-12 18:01:34 +08:00
parent 81d06cc4d5
commit 3e30a5ad0c
2 changed files with 6 additions and 6 deletions

View File

@ -18,7 +18,7 @@ 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. For example, grouping data by label location, taking the average voltage within each group.
```sql
select avg(voltage) from meters partition by location
select location, avg(voltage) from meters partition by location
```
A PARTITION BY clause is processed as follows:
@ -28,12 +28,12 @@ A PARTITION BY clause is processed as follows:
- The PARTITION BY clause can be used together with a window clause or GROUP BY clause. In this case, the window or GROUP BY clause takes effect on every partition. For example, the following statement partitions the table by the location tag, performs downsampling over a 10 minute window, and returns the maximum value:
```sql
select max(current) from meters partition by location interval(10m)
select _wstart, location, 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. For example, calculate the average voltage of each meter every 10 minutes£º
```sql
select avg(voltage) from meters partition by tbname interval(10m)
select _wstart, tbname, avg(voltage) from meters partition by tbname interval(10m)
```
## Windowed Queries

View File

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