
MySQL查询统计次数简单的语句肯定是这样了:
select a.name,count_neg,count_plus from
(select count(id) as count_plus,name from score2 where score >=60 group by name) a,
(select count(id) as count_neg,name from score2 where score <=60 group by name) b
where a.name=b.name
即必须至少用2个语句。
今天刚好碰到发现mysql支持if,那就创造性的用if来实现吧:
select name, sum(if(score>=60,1,0)),sum(if(score<60,1,0)) from score2 group by name
单个select语句实现MySQL查询统计次数的方法简单吧。
原理就是大于60,就赋值为1,那么sum就是计数了。
根据查询相关资料显示,在mysql中套用COUNT(CASEWHEN`支付状态`='已支付'AND`订单金额`>100THEN1END)这个公式,即可统计出订单金额在3000元以上的订单数。欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)