mysq 条件分组统计_分组统计每个人的bug权值



题:请计算出每个人处理的bug的权值,pri为1计3分,为2计2分,为3计1分,为4计0.5分。


#计算Bug权值,join方法一:
select  T1.openedBy as '姓名'  ,T1.A*3+T2.B*2 as 'Bug权值' from (
SELECT openedBy  , count(*) as 'A'
FROM `zt_bug` 
WHERE `openedDate` > '2016-01-01'   and pri = 1
group by `openedBy` 
        ) T1
left join 
(SELECT openedBy  , count(*) as 'B'
FROM `zt_bug` 
WHERE `openedDate` > '2016-01-01' and pri = 2
group by `openedBy`
)  T2
on T1.openedBy = T2.openedBy


#计算Bug权值,case方法2.1:
select resolvedby ,  
count(
case pri 
when 1 then 3 
when 2 then 2
when 3 then 1
when 4 then 0.5
else 0 end  
)
as 'bug权值'
from zt_bug
group by resolvedBy

#计算Bug权值,case方法2.2:
select resolvedby ,  
count(
case 
when pri = 1 then 3 
when pri = 2 then 2
when pri = 3 then 1
when pri = 4 then 0.5
else '' end  
)
as 'bug权值'
from zt_bug
group by resolvedBy

#计算Bug权值,if方法3:
select resolvedby ,
count(if(pri = 1,3,if(pri = 2,2,if(pri = 3,1,if(pri = 4,0.5,0)))))  
from zt_bug
group by resolvedBy

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

蜕变之痛

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

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

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

打赏作者

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

抵扣说明:

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

余额充值