1132
做这道题,我的感受是,大体思路是对的,但是由于对于题目意识的理解不够清楚,细节上容易出错。




select round(avg(average)*100,2) average_daily_percent from ( select a.action_date,ifnull(part_count,0)/all_count average from ( select action_date,count(distinct post_id) all_count from Actions where extra='spam' group by action_date ) a left join ( select action_date,count(distinct a.post_id) part_count from Actions a left join Removals b on a.post_id=b.post_id where b.post_id is not null and a.extra='spam' group by action_date ) b on a.action_date=b.action_date ) c;
易错点1:如果某一天有垃圾帖子,但是没有被移除。这一天的垃圾广告移除率是0%,我们在算总体平均数的时候不能忽视这个0,这个0也要算进去。比如(2+0)/(1+1)=1,这是和2/1=2不一样的。
易错点2:题目说这张表没有主键,并且可能存在重复的行。即比如某一天垃圾广告里面,有两个post_id为1的垃圾广告,这时只算一个。

浙公网安备 33010602011771号