yiguolei commented on code in PR #2670:
URL: https://github.com/apache/doris-website/pull/2670#discussion_r2235615671
##########
docs/sql-manual/sql-functions/aggregate-functions/avg.md:
##########
@@ -25,29 +25,97 @@ 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
+) distributed by hash (k1) buckets 1
+properties ("replication_num"="1");
+insert into t1 values
+ (1, 222.222, '1.5', 'test', null),
+ (2, 444.444, '2.5', '1', null),
+ (3, null, '3.5', '2', null);
```
+
+```sql
+select avg(k1) from t1;
+```
+
+The average of [1,2,3] is 2.
+
```text
-+---------------------+--------------------+
-| datetime | avg(`cost_time`) |
-+---------------------+--------------------+
-| 2019-07-03 21:01:20 | 25.827794561933533 |
-+---------------------+--------------------+
++---------+
+| avg(k1) |
++---------+
+| 2 |
++---------+
```
+
```sql
-SELECT datetime, AVG(distinct cost_time) FROM log_statis group by datetime;
+select avg(kd) from t1;
```
+The average of [222.222,444.444,null] is 333.333.
+
```text
-+---------------------+---------------------------+
-| datetime | avg(DISTINCT `cost_time`) |
-+---------------------+---------------------------+
-| 2019-07-04 02:23:24 | 20.666666666666668 |
-+---------------------+---------------------------+
++-----------+
+| avg(kd) |
++-----------+
+| 333.33300 |
++-----------+
```
+
+```sql
+select avg(kstr) from t1;
+```
+
+The input Varchar type will be implicitly converted to Double.
Review Comment:
我们这个隐式的转换,都是到double 吗?
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]