select tag,sum(if(if_retweet=1,1,0)) as retweet_cut, round(sum(if(if_retweet=1,1,0))/count(1),3) as retweet_rate from ( select tag,start_time,if_retweet, max(date_format(start_time,'%Y%m%d'))over(order by start_time desc) as max_time from tb_video_info t1 join tb_user_video_log t2 on t1.video_id = t2.video_id ) t where datediff(max_time,date_format(start_time,'%Y%m%d')) <= 29 group by tag order by retweet_rate desc