聚合函数特点:只有一个返回值
一般用在数据表中的某些信息。
1、mysql> SELECT * FROM test;
+----+----------+
| id | username |
+----+----------+
| 1 | John |
| 2 | Mary |
| 3 | 1%Lily |
| 4 | Rose |
| 5 | NULL |
| 6 | Mary |
| 7 | Mary |
| 8 | H |
+----+----------+
8 rows in set (0.00 sec)
mysql> SELECT AVG(id) FROM test;
+---------+
| AVG(id) |
+---------+
| 4.5000 |
+---------+
1 row in set (0.00 sec)
2、
mysql> SELECT COUNT(id) AS counts FROM test;
+--------+
| counts |
+--------+
| 8 |
+--------+
1 row in set (0.00 sec)
3、
mysql> SELECT MAX(id) AS counts FROM test;
+--------+
| counts |
+--------+
| 8 |
+--------+
1 row in set (0.00 sec)
mysql> SELECT MIN(id) AS counts FROM test;
+--------+
| counts |
+--------+
| 1 |
+--------+
1 row in set (0.00 sec)
mysql> SELECT SUM(id) AS counts FROM test;
+--------+
| counts |
+--------+
| 36 |
+--------+
一般不会对数据表中的id进行操作,这里只是...