不需要Join,直接进行单表查询+子查询过滤

异常的邮件概率

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

  1. 首先找出黑名单的user:
    select id
    from user
    where is_blacklist = 1

2.然后查询email表:

select 
    date,
    round((sum(type='no_completed') / COUNT(*)),3) as p
from email
where send_id and receive_id not in (
    select id
    from user
    where is_blacklist = 1
)
GROUP BY date
order by date asc;

其中round函数是保留几位精度;
count函数中只能传进去列,不能传条件进去;
sum函数对满足条件的进行求和,sum可以传进去if判断,也可以直接传进去条件,满足的+1;

全部评论

相关推荐

每晚夜里独自颤抖:这个在牛客不是老熟人了吗
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

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