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

异常的邮件概率

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

-- round(a,3) 3位小数
-- coalesce(a) 防止计算返回null
sum()/count() 窗口函数

select
    e.date,
    round(
        coalesce(
            sum(
                case
                    when e.type = 'no_completed' then 1
                    else 0
                end
            ) / count(e.type)
        ),
        3
    ) as p
from
    email as e
where
    e.send_id in (
        select
            id
        from
            user as u
        where
            u.is_blacklist = 0
    )
    and e.receive_id in (
        select
            id
        from
            user as u
        where
            u.is_blacklist = 0
    )
group by
    e.date
order by
    e.date asc;

全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 12:02
ssob上原来真有BOSS啊
硫蛋蛋:这种也是打工的,只不是是给写字楼房东打工
点赞 评论 收藏
分享
流浪的神仙:无恶意,算法一般好像都得9硕才能干算法太卷啦
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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