不需要Join,直接进行单表查询+子查询过滤
异常的邮件概率
http://www.nowcoder.com/practice/d6dd656483b545159d3aa89b4c26004e
- 首先找出黑名单的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;