MYSQL统计

mysql统计同一字段下,不同值的总数的方法:

basebandBoard为字段,BPN2和CCE1等是为字段的多个值,这里进行统计。

方法一:

use gc;
select basebandBoard,count(basebandBoard) co from four where basebandBoard='CCE1';
select basebandBoard,count(basebandBoard) co from four where basebandBoard='BPN2';
select basebandBoard,count(case when basebandBoard='BPN2' then 1 end) as BPN2,
count(case when basebandBoard='CCE1' then 1 end) as CCE1,
count(case when basebandBoard='BPP1' then 1 end) as BPP1
from four
group by basebandBoard;

 效果:

 

方法二:

select count(if(basebandBoard='BPN2',basebandBoard,null)),count(if(basebandBoard='CCE1',basebandBoard,null)),count(if(basebandBoard='BPP1',basebandBoard,null)) from four;

 

效果:【这样的显示可以有助于知道if的用法,后续实际使用可以取别名】

命别名后:

select count(if(basebandBoard='BPN2',basebandBoard,null)) BPN2,count(if(basebandBoard='CCE1',basebandBoard,null)) BPN2,count(if(basebandBoard='BPP1',basebandBoard,null)) BPP1 from four;

效果:

 

转载于:https://www.cnblogs.com/ciscolee/p/11178864.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值