用sum直接计算失败的个数

异常的邮件概率

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

select date, round(sum(type = "no_completed") / count(*), 3) as p
from email as t1
    join user as t2 on t1.send_id = t2.id
    join user as t3 on t1.receive_id = t3.id
where t2.is_blacklist = 0 and t3.is_blacklist = 0
group by date
order by date;
全部评论
为什么用SUM是对的呢?这算是计数吗?
2 回复 分享
发布于 2021-01-20 17:56
sum(type = "no_completed")*1.0 否则无法通过
1 回复 分享
发布于 2021-06-19 23:54
为什么round(sum(e.type = 'no_completed')/count(e.type),3)中的sum不能换成count?
4 回复 分享
发布于 2021-11-12 09:03
我为什么想不到这种编写思路呢?我什么只能是想到最常规的先取发送失败的,再取总的,最后连起来算失败率,我要怎么做才能第一时间就想到你这种写法呢
4 回复 分享
发布于 2021-07-04 13:47
简化一下 select e.date,round(sum(e.type = 'no_completed')/count(e.type),3) as pc1 from email as e, user as u1, user as u2 where e.send_id = u1.id and e.receive_id = u2.id and u1.is_blacklist = 0 and u2.is_blacklist = 0 group by e.date order by e.date
2 回复 分享
发布于 2021-10-12 15:46
大佬,真大佬!
点赞 回复 分享
发布于 2022-08-19 10:05 陕西
大佬思路
点赞 回复 分享
发布于 2022-07-20 00:04
sum(type = "no_completed") 不知道sum 还有这种用法,妈的 想了一个小时
点赞 回复 分享
发布于 2022-06-29 19:50
膜拜
点赞 回复 分享
发布于 2022-05-17 00:02
好清晰啊,膜拜大佬
点赞 回复 分享
发布于 2022-04-09 22:18
很奇怪,我使用 ROUND(SUM(IF(type = 'completed', 0, 1) / COUNT(*), 3),就会报错
点赞 回复 分享
发布于 2022-02-08 11:18
select date, round(sum(type = "no_completed") / count(*), 3) as p from email where send_id in (select id from user where is_blacklist = 0) and receive_id in (select id from user where is_blacklist = 0) group by date order by date
点赞 回复 分享
发布于 2021-07-20 21:30
总是想不到直接判断,上来就是各种联接,感谢大佬!
点赞 回复 分享
发布于 2021-03-21 21:32
同问
点赞 回复 分享
发布于 2021-01-30 13:46

相关推荐

评论
109
15
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务