diff --git a/docs/en/12-taos-sql/06-select.md b/docs/en/12-taos-sql/06-select.md index f1e19a5449..2606b183b8 100755 --- a/docs/en/12-taos-sql/06-select.md +++ b/docs/en/12-taos-sql/06-select.md @@ -259,7 +259,11 @@ The GROUP BY clause does not guarantee that the results are ordered. If you want ## PARTITION BY -The PARTITION BY clause is a TDengine-specific extension to standard SQL. This clause partitions data based on the part_list and performs computations per partition. +The PARTITION BY clause is a TDengine-specific extension to standard SQL introduced in TDengine 3.0. This clause partitions data based on the part_list and performs computations per partition. + +PARTITION BY and GROUP BY have similar meanings. They both group data according to a specified list and then perform calculations. The difference is that PARTITION BY does not have various restrictions on the SELECT list of the GROUP BY clause. Any operation can be performed within the group (constants, aggregations, scalars, expressions, etc.). Therefore, PARTITION BY is fully compatible with GROUP BY in terms of usage. All places that use the GROUP BY clause can be replaced with PARTITION BY. + +Because PARTITION BY does not require returning a row of aggregated data, it can also support various window operations after grouping slices. All window operations that need to be grouped can only use the PARTITION BY clause. For more information, see TDengine Extensions. diff --git a/docs/en/12-taos-sql/12-distinguished.md b/docs/en/12-taos-sql/12-distinguished.md index 502b7562f3..64687de9f3 100644 --- a/docs/en/12-taos-sql/12-distinguished.md +++ b/docs/en/12-taos-sql/12-distinguished.md @@ -16,7 +16,10 @@ When you query a supertable, you may need to partition the supertable by some di 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: @@ -28,7 +31,10 @@ A PARTITION BY clause is processed as follows: 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 diff --git a/docs/zh/12-taos-sql/06-select.md b/docs/zh/12-taos-sql/06-select.md index 04508ceede..23ae025610 100755 --- a/docs/zh/12-taos-sql/06-select.md +++ b/docs/zh/12-taos-sql/06-select.md @@ -259,7 +259,12 @@ GROUP BY å­å¥ä¸­çš„表达å¼å¯ä»¥åŒ…å«è¡¨æˆ–视图中的任何列,这些 ## PARTITION BY -PARTITION BY å­å¥æ˜¯ TDengine 特色语法,按 part_list 对数æ®è¿›è¡Œåˆ‡åˆ†ï¼Œåœ¨æ¯ä¸ªåˆ‡åˆ†çš„分片中进行计算。 +PARTITION BY å­å¥æ˜¯ TDengine 3.0ç‰ˆæœ¬å¼•å…¥çš„ç‰¹è‰²è¯­æ³•ï¼Œç”¨äºŽæ ¹æ® part_list 对数æ®è¿›è¡Œåˆ‡åˆ†ï¼Œåœ¨æ¯ä¸ªåˆ‡åˆ†çš„分片中å¯ä»¥è¿›è¡Œå„ç§è®¡ç®—。 + +PARTITION BY 与 GROUP BY 基本å«ä¹‰ç›¸ä¼¼ï¼Œéƒ½æ˜¯æŒ‰ç…§æŒ‡å®šåˆ—表进行数æ®åˆ†ç»„ç„¶åŽè¿›è¡Œè®¡ç®—,ä¸åŒç‚¹åœ¨äºŽ PARTITION BY 没有 GROUP BY å­å¥çš„ SELECT 列表的å„ç§é™åˆ¶ï¼Œç»„内å¯ä»¥è¿›è¡Œä»»æ„è¿ç®—(常é‡ã€èšåˆã€æ ‡é‡ã€è¡¨è¾¾å¼ç­‰ï¼‰ï¼Œå› æ­¤åœ¨ä½¿ç”¨ä¸Š PARTITION BY 完全兼容 GROUP BY,所有使用 GROUP BY å­å¥çš„地方都å¯ä»¥æ›¿æ¢ä¸º PARTITION BY。 + +因为 PARTITION BY 没有返回一行èšåˆæ•°æ®çš„è¦æ±‚,因此还å¯ä»¥æ”¯æŒåœ¨åˆ†ç»„切片åŽçš„å„ç§çª—å£è¿ç®—,所有需è¦åˆ†ç»„进行的窗å£è¿ç®—都åªèƒ½ä½¿ç”¨ PARTITION BY å­å¥ã€‚ + è¯¦è§ [TDengine 特色查询](../distinguished) diff --git a/docs/zh/12-taos-sql/12-distinguished.md b/docs/zh/12-taos-sql/12-distinguished.md index 98bfd3567a..a9fa1b6bb1 100755 --- a/docs/zh/12-taos-sql/12-distinguished.md +++ b/docs/zh/12-taos-sql/12-distinguished.md @@ -16,7 +16,11 @@ TDengine æä¾›çš„特色查询包括数æ®åˆ‡åˆ†æŸ¥è¯¢å’Œæ—¶é—´çª—å£åˆ‡åˆ†æŸ¥ PARTITION BY part_list ``` -part_list å¯ä»¥æ˜¯ä»»æ„的标é‡è¡¨è¾¾å¼ï¼ŒåŒ…括列ã€å¸¸é‡ã€æ ‡é‡å‡½æ•°å’Œå®ƒä»¬çš„组åˆã€‚ +part_list å¯ä»¥æ˜¯ä»»æ„的标é‡è¡¨è¾¾å¼ï¼ŒåŒ…括列ã€å¸¸é‡ã€æ ‡é‡å‡½æ•°å’Œå®ƒä»¬çš„组åˆã€‚ä¾‹å¦‚ï¼Œå°†æ•°æ®æŒ‰æ ‡ç­¾ location è¿›è¡Œåˆ†ç»„ï¼Œå–æ¯ä¸ªåˆ†ç»„内的电压平å‡å€¼ï¼š +```sql +select avg(voltage) from meters partition by location +``` + TDengine 按如下方å¼å¤„ç†æ•°æ®åˆ‡åˆ†å­å¥ï¼š @@ -27,7 +31,11 @@ TDengine 按如下方å¼å¤„ç†æ•°æ®åˆ‡åˆ†å­å¥ï¼š ```sql 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) +``` + ## 窗å£åˆ‡åˆ†æŸ¥è¯¢