This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris-website.git


The following commit(s) were added to refs/heads/master by this push:
     new 27b6c6bdf4b update doc of function avg (#2670)
27b6c6bdf4b is described below

commit 27b6c6bdf4b217db1d521a97e6f3bad271968980
Author: Pxl <[email protected]>
AuthorDate: Thu Jul 31 14:41:51 2025 +0800

    update doc of function avg (#2670)
    
    ## Versions
    
    - [x] dev
    - [ ] 3.0
    - [ ] 2.1
    - [ ] 2.0
    
    ## Languages
    
    - [x] Chinese
    - [x] English
    
    ## Docs Checklist
    
    - [ ] Checked by AI
    - [ ] Test Cases Built
---
 .../sql-functions/aggregate-functions/avg.md       | 107 +++++++++++++++++---
 .../sql-functions/aggregate-functions/avg.md       | 109 ++++++++++++++++++---
 2 files changed, 191 insertions(+), 25 deletions(-)

diff --git a/docs/sql-manual/sql-functions/aggregate-functions/avg.md 
b/docs/sql-manual/sql-functions/aggregate-functions/avg.md
index 3c1071145ee..a342b615e27 100644
--- a/docs/sql-manual/sql-functions/aggregate-functions/avg.md
+++ b/docs/sql-manual/sql-functions/aggregate-functions/avg.md
@@ -25,29 +25,112 @@ AVG([DISTINCT] <expr>)
 ## Return Value
 
 Returns the average value of the selected column or expression. If all records 
in the group are NULL, the function returns NULL.
+For decimal type input, return value will be decimal as well, other numric 
type will return double type.
 
 ## Example
 
 ```sql
-SELECT datetime, AVG(cost_time) FROM log_statis group by datetime;
+-- setup
+create table t1(
+        k1 int,
+        kd decimalv3(10, 5),
+        kstr varchar(100),
+        kstr_invalid varchar(100),
+        knull int,
+        kbigint bigint
+) distributed by hash (k1) buckets 1
+properties ("replication_num"="1");
+insert into t1 values 
+    (1, 222.222, '1.5', 'test', null, 100),
+    (2, 444.444, '2.5', '1', null, 100),
+    (3, null, '3.5', '2', null, 1);
 ```
 
+
+```sql
+select avg(k1) from t1;
+```
+
+The average of [1,2,3] is 2.
+
+```text
++---------+
+| avg(k1) |
++---------+
+|       2 |
++---------+
+```
+
+
+```sql
+select avg(kd) from t1;
+```
+
+The average of [222.222,444.444,null] is 333.333.
+
+```text
++-----------+
+| avg(kd)   |
++-----------+
+| 333.33300 |
++-----------+
+```
+
+```sql
+select avg(kstr) from t1;
+```
+
+The input Varchar type will be implicitly converted to Double.
+The average of [1.5,2.5,3.5] is 2.5.
+
+```text
++-----------+
+| avg(kstr) |
++-----------+
+|       2.5 |
++-----------+
+```
+
+```sql
+select avg(kstr_invalid) from t1;
+```
+
+Invalid strings will be converted to NULL values during implicit conversion.
+The average of [null,1,2] is 1.5.
+
 ```text
-+---------------------+--------------------+
-| datetime            | avg(`cost_time`)   |
-+---------------------+--------------------+
-| 2019-07-03 21:01:20 | 25.827794561933533 |
-+---------------------+--------------------+
++-------------------+
+| avg(kstr_invalid) |
++-------------------+
+|               1.5 |
++-------------------+
 ```
 
 ```sql
-SELECT datetime, AVG(distinct cost_time) FROM log_statis group by datetime;
+select avg(knull) from t1;
 ```
 
+For cases where all input data are NULL values, return NULL value.
+
 ```text
-+---------------------+---------------------------+
-| datetime            | avg(DISTINCT `cost_time`) |
-+---------------------+---------------------------+
-| 2019-07-04 02:23:24 |        20.666666666666668 |
-+---------------------+---------------------------+
++------------+
+| avg(knull) |
++------------+
+|       NULL |
++------------+
 ```
+
+```sql
+select avg(distinct kbigint) from t1;
+```
+
+After deduplication, [100,100,1] becomes [100,1], with an average of 50.5.
+
+```text
++-----------------------+
+| avg(distinct kbigint) |
++-----------------------+
+|                  50.5 |
++-----------------------+
+```
+
diff --git 
a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/aggregate-functions/avg.md
 
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/aggregate-functions/avg.md
index 9b6dfde9c5b..df8ff06d4b7 100644
--- 
a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/aggregate-functions/avg.md
+++ 
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/aggregate-functions/avg.md
@@ -24,30 +24,113 @@ AVG([DISTINCT] <expr>)
 
 ## 返回值
 
-返回所选列或表达式的平均值,如果组内的所有记录均为 NULL,则该函数返回 NULL
+返回所选列或表达式的平均值,如果组内的所有记录均为 NULL,则该函数返回 NULL 。
+对于 Decimal 类型的输入,返回值类型为 Decimal 。其他数值类型的返回值为 Double 。
 
 ## 举例
 
 ```sql
-SELECT datetime, AVG(cost_time) FROM log_statis group by datetime;
+-- setup
+create table t1(
+        k1 int,
+        kd decimalv3(10, 5),
+        kstr varchar(100),
+        kstr_invalid varchar(100),
+        knull int,
+        kbigint bigint
+) distributed by hash (k1) buckets 1
+properties ("replication_num"="1");
+insert into t1 values 
+    (1, 222.222, '1.5', 'test', null, 100),
+    (2, 444.444, '2.5', '1', null, 100),
+    (3, null, '3.5', '2', null, 1);
 ```
 
+
+```sql
+select avg(k1) from t1;
+```
+
+[1,2,3]的平均值为2。
+
+```text
++---------+
+| avg(k1) |
++---------+
+|       2 |
++---------+
+```
+
+
+```sql
+select avg(kd) from t1;
+```
+
+[222.222,444.444,null]的平均值为333.333。
+
+```text
++-----------+
+| avg(kd)   |
++-----------+
+| 333.33300 |
++-----------+
+```
+
+```sql
+select avg(kstr) from t1;
+```
+
+输入的 Varchar 类型会被隐式转换为 Double。
+[1.5,2.5,3.5]的平均值为2.5。
+
+```text
++-----------+
+| avg(kstr) |
++-----------+
+|       2.5 |
++-----------+
+```
+
+```sql
+select avg(kstr_invalid) from t1;
+```
+
+非法的字符串会在隐式转换中变成 NULL 值。
+[null,1,2]的平均值为1.5。
+
 ```text
-+---------------------+--------------------+
-| datetime            | avg(`cost_time`)   |
-+---------------------+--------------------+
-| 2019-07-03 21:01:20 | 25.827794561933533 |
-+---------------------+--------------------+
++-------------------+
+| avg(kstr_invalid) |
++-------------------+
+|               1.5 |
++-------------------+
 ```
 
 ```sql
-SELECT datetime, AVG(distinct cost_time) FROM log_statis group by datetime;
+select avg(knull) from t1;
 ```
 
+对于输入数据均为 NULL 值的情况,返回 NULL 值。
+
 ```text
-+---------------------+---------------------------+
-| datetime            | avg(DISTINCT `cost_time`) |
-+---------------------+---------------------------+
-| 2019-07-04 02:23:24 |        20.666666666666668 |
-+---------------------+---------------------------+
++------------+
+| avg(knull) |
++------------+
+|       NULL |
++------------+
 ```
+
+```sql
+select avg(distinct kbigint) from t1;
+```
+
+[100,100,1]去重之后为[100,1],平均值为50.5。
+
+```text
++-----------------------+
+| avg(distinct kbigint) |
++-----------------------+
+|                  50.5 |
++-----------------------+
+```
+


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to