Syntax
AVG(([DISTINCT | ALL] expr)
Purpose
Returns the average value of the specified group, ignoring null values. You can use the DISTINCT option to return the average value of different expr values. If no rows match the condition, AVG() returns NULL.
Examples
obclient> SELECT * FROM oceanbasetest;
+----+------+------+
| id | ip | ip2 |
+----+------+------+
| 1 | 4 | NULL |
| 3 | 3 | NULL |
| 4 | 3 | NULL |
+----+------+------+
3 rows in set
obclient> SELECT avg(ip2), avg(ip), avg(distinct(ip)) FROM oceanbasetest;
+----------+---------+-------------------+
| avg(ip2) | avg(ip) | avg(distinct(ip)) |
+----------+---------+-------------------+
| NULL | 3.3333 | 3.5000 |
+----------+---------+-------------------+
1 row in set
obclient> SELECT avg(distinct(ip)),avg(ip),avg(ip2) FROM oceanbasetest;
+-------------------+---------+----------+
| avg(distinct(ip)) | avg(ip) | avg(ip2) |
+-------------------+---------+----------+
| 3.5000 | 3.3333 | NULL |
+-------------------+---------+----------+
1 row in set
