题目链接:点击打开链接
题目大意:略。
解题思路:略。
AC 代码
--解决方案(1) WITHt1AS(SELECTa.post_idaid, r.post_idrid, action_dateFROMActionsaLEFTJOINRemovalsrONa.post_id=r.post_idWHEREextra='spam'), t2AS(SELECTCOUNT(DISTINCTrid)/COUNT(DISTINCTaid) percentFROMt1GROUPBYaction_date) SELECTROUND(AVG(percent) *100, 2) average_daily_percentFROMt2--解决方案(2) SELECTROUND(AVG(IFNULL(remove.cnt, 0)/total.cnt) *100, 2) ASaverage_daily_percentFROM ( SELECTaction_date, COUNT(DISTINCTpost_id) AScntFROMactionsWHEREextra='spam'GROUPBYaction_date) totalLEFTJOIN ( SELECTaction_date, COUNT(DISTINCTpost_id) AScntFROMactionsWHEREextra='spam'ANDpost_idIN (SELECTpost_idFROMRemovals) GROUPBYaction_date) removeONtotal.action_date=remove.action_date