您可以AVG()
为此使用聚合函数。让我们首先创建一个表-
mysql> create table DemoTable ( Value1 int, Value2 int, Value3 int );
使用插入命令在表中插入记录-
mysql> insert into DemoTable values(10,20,30); mysql> insert into DemoTable values(13,15,18); mysql> insert into DemoTable values(21,31,41);
使用选择命令显示表中的记录-
mysql> select *from DemoTable;
这将产生以下输出-
+--------+--------+--------+ | Value1 | Value2 | Value3 | +--------+--------+--------+ | 10 | 20 | 30 | | 13 | 15 | 18 | | 21 | 31 | 41 | +--------+--------+--------+ 3 rows in set (0.00 sec)
以下是查询以显示单行中平均值的平均值-
mysql> select avg(Value1+Value2+Value3)/3.0 from DemoTable;
这将产生以下输出-
+-------------------------------+ | avg(Value1+Value2+Value3)/3.0 | +-------------------------------+ | 22.11111111 | +-------------------------------+ 1 row in set (0.00 sec)