1.聚合函数
函数 | 说明 |
---|---|
count([distinct] expr) | 返回查询到的数据的 数量 |
sum([distinct] expr) | 返回查询到的数据的 总和 |
avg([distinct] expr) | 返回查询到的数据的 平均值 |
max([distinct] expr) | 返回查询到的数据的 最大值 |
min([distinct] expr) | 返回查询到的数据的最小值 |
1.1 案例
如图为表的样式:
统计班级有多少个学生
select count(*) from student;
统计本次考试 语文成绩分数的个数
select count(distinct chinese) from student;
统计数学成绩的总分
select sum(math) from student;
统计各门课的平均分
select avg(chinese),avg(math),avg(english) from student;
返回英语的最高分和最低分
select max(english),min(english) from student;
返回英语成绩60分以上的最低分
select min(english) from student where english>60;