select c.t, sum(c.re) as retweet_cut, round(sum(c.re)/count(c.re),3) as retweet_rate from (select a.video_id, b.tag as t, a.start_time as time, a.if_retweet as re from tb_user_video_log a left join tb_video_info b on a.video_id = b.video_id) c where timestampdiff(day,c.time,(select MAX(start_time) from tb_user_video_log)) <= 29 group by c.t order by retweet_rate desc
- where语句:使用timestampdiff筛选最近一个月内的数据