SteveYurongSu commented on a change in pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#discussion_r762804595



##########
File path: 
docs/zh/UserGuide/IoTDB-SQL-Language/DML-Data-Manipulation-Language.md
##########
@@ -1019,6 +1019,67 @@ select count(status) from root.ln.wf01.wt01 group by 
([0,20),2ms,3ms), level=1;
 Total line number = 7
 It costs 0.004s
 ```
+#### 聚合查询嵌套表达式
+
+IoTDB 支持在 `select` 字句中执行由聚合查询和常量组成的任意嵌套表达式。
+
+**注意:**
+
+- 目前此功能尚不支持group by以及fill算子, 在后续版本会支持。
+- 表达式算术运算(+,-,*,/,%)不支持返回值为布尔类型以及文本类型的聚合函数
+
+##### 语法
+
+下面是聚合查询嵌套表达式子句的语法定义:
+
+```sql
+selectClause
+    : SELECT resultColumn (',' resultColumn)*
+    ;
+
+resultColumn
+    : expression (AS ID)?
+    ;
+
+expression
+    : '(' expression ')'
+    | '-' expression
+    | expression ('*' | '/' | '%') expression
+    | expression ('+' | '-') expression
+    | functionName '('timeSeriesSuffixPath')'
+    | number
+    ;
+```
+
+##### 示例
+
+输入:
+
+```sql
+select count(a),
+       count(b),
+       ((count(a) + 1) * 2 - 1) % 2 + 1.5,
+       -(count(a) + count(b)) * (count(a) * count(b)) + count(a) / count(b)
+from root.sg;
+```
+
+结果:
+
+```
++----------------+----------------+----------------------------------------------+------------------------------------------------------------------------------------------------------
+----------------+
+|count(root.sg.a)|count(root.sg.b)|((((count(root.sg.a) + 1) * 2) - 1) % 2) + 
1.5|(-count(root.sg.a) + count(root.sg.b) * (count(root.sg.a) * 
count(root.sg.b))) + (count(root.sg.a) / c
+ount(root.sg.b))|
++----------------+----------------+----------------------------------------------+------------------------------------------------------------------------------------------------------
+----------------+
+|               4|               3|                                           
2.5|                                                                            
                        -8
+2.66666666666667|
++----------------+----------------+----------------------------------------------+------------------------------------------------------------------------------------------------------
+----------------+

Review comment:
       hmm.. something's wrong with the format.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to