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

异常的邮件概率

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;

全部评论

相关推荐

04-17 10:16
门头沟学院 Java
小浪_coder:24届很难找了,马上25的都毕业了还有很多没找到的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务