先展示一波代码,再写思路 SELECT a.video_id, ROUND(SUM(if(date_sub(end_time,interval duration second) >= start_time,1,0))/COUNT(start_time),3) as avg_comp_play_rate FROM tb_user_video_log as a LEFT JOIN tb_video_info as b ON a.video_id = b.video_id WHERE year(start_time) = '2021' GROUP by a.video_id ORDER BY ...