查询语句之聚合函数

sql中常用的聚合函数包含有五个:MAX(最大值)、MIN(最小值)、AVG (平均值)、SUM (和)、COUNT(数量

1、男学生出生日期的最大值和最小值:
SELECT select max(sBirthday),min(sBirthday) from student where sSex='男'


2、平均成绩
select avg(english) from score

3、查询学生表中的学生平均年龄,并添加别名
select AVG(sAge) as 平均年龄 from student 

4、sum函数求和
select sum(sAge) as 年龄和 from student 

5、count求个数和
select count(*) as 总人数 from student 

注 :
聚合函数不能出现在Where字句中

相关文章

迭代器模式(Iterator)迭代器模式(Iterator)[Cursor]意图...
高性能IO模型浅析服务器端编程经常需要构造高性能的IO模型,...
策略模式(Strategy)策略模式(Strategy)[Policy]意图:定...
访问者模式(Visitor)访问者模式(Visitor)意图:表示一个...
命令模式(Command)命令模式(Command)[Action/Transactio...
生成器模式(Builder)生成器模式(Builder)意图:将一个对...