MySQL数据库之聚合函数

聚合函数

  • 聚合函数
    • sum() 求和
    • avg() 求平均值
    • max() 求最大值
    • min() 求最小值
    • count() 求记录数
MariaDB [sel]> select max(chinese) '语文最高分' from grades;
+------------+
| 语文最高分  |
+------------+
|         98 |
+------------+
# `1 row in set (0.010 sec)`

MariaDB [sel]> select max(math) 数学最高分,min(math) 数学最低分,sum(math) 数学总分,avg(math) 数学平均分,count(*) 考试人数 from grades;
+------------+------------+----------+------------+----------+
| 数学最高分  | 数学最低分  | 数学总分  | 数学平均分 | 考试人数  |
+------------+------------+----------+------------+----------+
|         96 |         91 |      375 |    93.7500 |        4 |
+------------+------------+----------+------------+----------+
# `1 row in set (0.000 sec)`
原文地址:https://www.cnblogs.com/SharkJiao/p/14137796.html