mysql中having的例子_mysql group by/having/distinct 查询使用例子

表的内容如下:

b808902a26c1dcc3e5cb0bf635fd4280.png

//查询单分数最高的人ID

select stuid,max(score) from stu_select_class;

// 查询各科总分2-3名的学生

select stuid, sum(score) from stu_select_class group by stuid  limit 1,2;

//查询每科的最高分学生

select classname,stuid,max(score) from stu_select_class group by classname;

//查询总分低于140的学生

select stuid, sum(score) from stu_select_class group by stuid having sum(score)<140;

//查询总平均分在60-80的学生

select stuid, avg(score) from stu_select_class group by stuid having avg(score) between 60 and 80;

//查询。。。。的学生 select stuid, sum(score),avg(score) from stu_select_class group by stuid having sum(score)<140 and avg(score) <80; //查询总分。。的学生人数。 select distinct count( stuid)  from stu_select_class group by stuid having sum(score)<140 and avg(score) <80; //查询。。。的学生人数 select count(distinct stuid) from stu_select_class where classname='english' and score <100;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值