[Mysql 查询语句]——集合函数

count() 统计记录条数

select count(*) from student;
+----------+
| count(*) |
+----------+
|        4 |
+----------+

 

sum()求字段总和

(1) sum函数只能计算数值类型的字段:int、float、double、decimal等
(2) 不能用于计算字符类型字段,结果都为0

select sum(age) from student;
+----------+
| sum(age) |
+----------+
|      104 |
+----------+

 

avg()求字段平均数

select avg(age) from student;
+----------+
| avg(age) |
+----------+
|  26.0000 |
+----------+

 

max()求字段最大值

select max(num) from student;
+----------+
| max(num) |
+----------+
|        4 |
+----------+

 

min()求字段最小值

select min(num) from student;
+----------+
| min(num) |
+----------+
|        1 |
+----------+

 

posted @ 2016-08-04 19:11  Jelly_lyj  阅读(754)  评论(0编辑  收藏  举报