mysql的合计/统计函数

合计/统计函数

count函数

select count(*) from student;
select count(*) from student where math > 90;
  • count(*)和count(列)的区别
    • count(*)返回满足条件的记录的行数
    • count(列)统计满足条件的某列有多少个,但是会排除为null

sum函数

  • sum函数仅对数值有作用,否则会报错
  • 对于多列求和 , 不能少。
-- 统计一个班级的数学总成绩
select sum(math) from student;
-- 统计一个班级的各科总成绩
select sum(english),sum(math),sum(chinese) from student;
-- 统计一个班级的三科总成绩
select sum(english+math+chinese) from student;
-- 统计一个班级的语文平均分
select sum(chinese) / count(*) from student;

avg函数

-- 统计数学平均分
select avg(math) from student;
-- 统计总成绩平均分
select avg(math + english + chinese) from student;

max/min函数

-- 求班级最高分和最低分
select max(math + english + chinese) , min(math + chinese + english) from student;
-- 求班级数学最高分和最低分
select max(math),min(math) from student;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GaoJa

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值