一. AVG()
AVG():平均值
mysql> SELECT AVG(2.0,3); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '3)' at line 1 mysql> SELECT AVG(id) FROM test; +---------+ | AVG(id) | +---------+ | 3.5000 | +---------+ 1 row in set (0.00 sec)
刚开始报错是因为聚合函数只能用于数据表中的信息,比如id
二. COUNT()
COUNT():计数
mysql> SELECT COUNT(id) FROM test; +-----------+ | COUNT(id) | +-----------+ | 6 | +-----------+ 1 row in set (0.00 sec)
三. MAX()
MAX():最大值
mysql> SELECT MAX(id) FROM test; +---------+ | MAX(id) | +---------+ | 6 | +---------+ 1 row in set (0.00 sec)
四. MIN()
MIN():最小值
mysql> SELECT MIN(id) FROM test; +---------+ | MIN(id) | +---------+ | 1 | +---------+ 1 row in set (0.00 sec)
五. SUM()
SUM():求和
mysql> SELECT SUM(id) FROM test; +---------+ | SUM(id) | +---------+ | 21 | +---------+ 1 row in set (0.00 sec)
请登录之后再进行评论