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

异常的邮件概率

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

mysql条件判断语句
1、

if(条件表达式,值1,值2);
if 条件语句1 then 语句1;
elseif 条件语句2 then 语句2;
...
else 语句n;
end if;

2、

case 表达式
when 值1 then 结果1或者语句1(如果是语句需要加分号)
when 值2 then 结果2或者语句2
...
else 结果n或者语句n
end [case] (如果是放在begin end之间需要加case,如果在select后则不需要)

本题写法

select e.date
,round(sum(case e.type when 'completed' then 0 else 1 end)*1.0/ count(*),3) as p
from email as e
where e.send_id not in(select id from user where is_blacklist=1)
      and e.receive_id not in(select id from user where is_blacklist=1)
group by e.date
order by e.date;
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务