Mysql常用函数(count,sum,max,min,avg)讲解
Person表全部示例数据
select * from person;

1.count() 函数讲解
例1:查询统计表中总共有多少条数据
select count(*) from person;

例2:结合分组GROUP BY语句使用:查询男,女,妖分别有多少人
select sex,count(*) from person group by sex;

2.sum() 求和函数
例1:查询表中所有人加起来有多少岁
select sum(age) from person;

例2:结合分组GROUP BY语句使用:查询男,女,妖分别总共有多少岁
select sex,sum(age) from person group by sex;

3.max() 求最大值函数
例1:查询表中年龄最大多少岁
select max(age) from person;

例2:结合分组GROUP BY语句使用:查询男,女,妖中年龄最大的多少岁
select sex,max(age) from person group by sex;

4.min() 求最小值函数
例1:查询表中年龄最小多少岁
select min(age) from person;

例2:结合分组GROUP BY语句使用:查询男,女,妖中年龄最小的多少岁
select sex,min(age) from person group by sex;

5.avg() 函数讲解
例1:查询表中平均年龄
select avg(age) from person;

例2:结合分组GROUP BY语句使用:查询男,女,妖各性别平均年龄
select sex,avg(age) from person group by sex;

扫二维码关注博主微信公众号👇
