题解 | #异常的邮件概率#

异常的邮件概率

http://www.nowcoder.com/practice/d6dd656483b545159d3aa89b4c26004e

思路:首先要筛选出正常用户,就需要合并user和email表然后用where子查询;其次就是分组计算,使用group by date;难点在于概率的计算,每天发邮件的总数很好计算,关键是怎么计算发送不成功的个数,这里采用讨论区大佬的方法:sum(case t2.type when 'completed' then 0 else 1 end)
【代码】
select t.date, round(sum(case t.type when 'completed' then 0 else 1 end) / count(t.type),3) as p
from
(select e.type, e.date from
email as e left join user as u1 on e.send_id = u1.id
left join user as u2 on e.receive_id = u2.id
where u1.is_blacklist =0 and u2.is_blacklist =0
) as t
group by t.date
order by t.date
【怎么计算发送不成功的概率】
1.round(sum(type = "no_completed") / count(), 3) as p
2.round(sum(case t2.type when 'completed' then 0 else 1 end)/count(
),3) as p

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务