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

select
    date,
    round(sum(type = "no_completed") * 1.0 / count(type), 3) p
from
    (
        select
            *
        from
            email
        where
            send_id not in (
                select
                    id
                from
                    user
                where
                    is_blacklist = 1
            )
            and receive_id not in (
                select
                    id
                from
                    user
                where
                    is_blacklist = 1
            )
    ) t
group by date
order by date

上述 ...and... 语句可以直接使用 join 进行联立获取;

对于 sum 来代替 count 的原因:

count(条件表达式) 无论是否满足条件表达式,只要非 null 值都会加 1,而 sum(条件表达式) 则符合正常逻辑。

使用 count 可以如下方式

count(type = 'no_completed' or null)
count(case when type = 'no_completed' then 1 else null end)
全部评论

相关推荐

看到这个内容真是闹麻了。。。。。。现在有了AI以后很多人面试都会作弊吗? 那对老老实实面试的人岂不是不公平....
程序员牛肉:公平那是对小孩子讲的童话故事,成年人的世界只有能不能接受失败的后果。 你要是能接受面试作弊被发现之后多家公司联合永久拉黑的后果,你就搞。
点赞 评论 收藏
分享
牛客84809583...:举报了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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