首页 > 数据库技术 > 详细

关系型数据库———聚合函数与分组

时间:2016-05-15 13:57:14      阅读:147      评论:0      收藏:0      [点我收藏+]

count:统计行数

select count(*) from student 

select count(age) from student  /*会不计null值*/

sum:返回列中值的和,会自动跳过null值(数值+null=null)

select sum(age) from student

avg:返回结果集中的所有值的平均值

select avg(age)from student

max/min:返回所有值中的最大/小值

select max(age) from student

 

Group by :数据分组查询

select  age,name,count(*) from student Group by age  /*以年龄段进行分组查询,并且统计每个年龄段有多少人*/

having:在分组后再次对数据进行过滤

select  age,name,count(*) from student Group by age having age=21

 

关系型数据库———聚合函数与分组

原文:http://www.cnblogs.com/JackieADBM/p/5495008.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!