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

异常的邮件概率

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

SELECT date,
    ROUND(
        AVG(IF(type='no_completed',1,0))
    ,3) 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

1、找到正常用户的发送和接收

WHERE send_id IN (
    SELECT id
    FROM user
    WHERE is_blacklist = 0
) AND receive_id IN (
    SELECT id
    FROM user
    WHERE is_blacklist = 0
)

2、计算每个日期未完成的概率

    ROUND(
        AVG(IF(type='no_completed',1,0))
    ,3) p
	
	GROUP BY date

3、按日期进行排序

SELECT date,
    ROUND(
        AVG(IF(type='no_completed',1,0))
    ,3) 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

全部评论

相关推荐

我是小红是我:学校换成中南
点赞 评论 收藏
分享
10-07 20:48
门头沟学院 Java
听说改名就会有offer:可能是实习上着班想到后面还要回学校给导师做牛马,看着身边都是21-25的年纪,突然emo了了
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务