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

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)
全部评论

相关推荐

点赞 评论 收藏
分享
03-26 22:55
门头沟学院 Java
烤冷面在迎接:河南byd,应该就是郑大了。不过24届计算机是特殊情况,那年除了九✌和强2,以及两三个关系够硬的双非,其他的都是炮灰,感觉是十几年来互联网行业最烂的一年,如果想了解最新的就业情况,得找现在的大四。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务