mysql之count,max,min,sum,avg,celing,floor

写在前面

昨天去青龙峡玩了一天,累的跟狗似的。不过还好,最终也算登到山顶了,也算来北京后征服的第三座山了。这里也唠叨一句,做开发这行,没事还是多运动运动,对自己还是很有好处的,废话少说,还是折腾折腾sql语句吧。

系列文章

mysql之创建数据库,创建数据表

mysql之select,insert,delete,update

mysql之group by,order by

count

计数,经常和group by语句搭配使用,此时,可以这样理解,分组后,该分组的个数。还以之前的数据表tb_student为例。

1、计算同一天入学的学生个数。

use school;
-- 计算同一天入学的学生个数。
select count(1) as `count` ,date(createdate) as goSchoolDate from tb_student group by date(createdate);

MAX

1、最大的id

1 use school;
2 select max(id) from tb_student;

Min

1、最小id

use school;
select min(id) from tb_student;

SUM

1、求出所有学生的年龄和

use school;
select sum(age) from tb_student;

AVG

1、求所有学生的年龄平均值

use school;
select avg(age) from tb_student;

celing

celing翻译过来就是“天花板”的意思,意思就是,不管小数点后面是什么,就往上进位。比如上面的年龄平均值

use school;
select ceiling(avg(age))  from tb_student;

当然和天花板对应的还有floor函数,当然意思就是相反的了。

floor

use school;
select floor(avg(age))  from tb_student;

总结

这里总结了常见的数学中一些函数,这些函数在做统计的时候是非常常用的。

posted @ 2015-05-24 10:47  wolfy  阅读(2408)  评论(0编辑  收藏  举报