Syntax
AVG(([DISTINCT ALL] expr)
Purpose
You can call this function to return the average value of a specified group. Null values are ignored. The DISTINCT option can be used to return the average of distinct values of expr. If no matching row is found, AVG() returns NULL.
Examples
obclient> SELECT * FROM oceanbasetest;
+----+------+------+
id ip ip2
+----+------+------+
1 4 NULL
3 3 NULL
4 3 NULL
+----+------+------+
3 rows in set (0.01 sec)
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 (0.00 sec)
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 (0.00 sec)