首页 > 其他 > 详细

8.聚合函数

时间:2016-10-14 07:01:56      阅读:169      评论:0      收藏:0      [点我收藏+]
--聚合函数--
--max():求指定数据范围中的最大值:可以对任意类型进行聚合,如果是非数值么就按值的拼音进行排序
--min():求指定数据范围中的最小值:可以对任意类型进行聚合,如果是非数值么就按值的拼音进行排序
--avg:求指定数据范围中的平均值,它只能对数值进行聚合,不能对日期进行聚合
--sum:求指定数据范围中的和,它只能对数值进行聚合,不能对日期进行聚合
--count:求满足条件的记录数,与字段没有任何关系

select COUNT(*) from Student where ClassId=6
--查询年龄最大的学员 年龄值越大就越小
select min(BornDate) from Student
select max(BornDate) from Student
select SUM(StudentName) from Student
select min(StudentName) from Student
select max(StudentName) from Student
select max(BornDate) from Student
select avg(BornDate) from Student
--查询科目ID是的学员的总分
select SUM(StudentResult) from Result where SubjectId=1
--平均分
--在sql server中,null是指不知道是什么值。聚合函数会过滤掉null值
select avg(StudentResult*1.0) from Result where SubjectId=1 and StudentResult is not null

select * from Student order by StudentName

 

8.聚合函数

原文:http://www.cnblogs.com/justqi/p/5958737.html

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