Select b.video_id, 
FORMAT(sum(case when timestampdiff(second,start_time,end_time) >=duration then 1
else 0 end)/count(*),3) as avg_comp_play_rate
FROM tb_video_info a
join tb_user_video_log b ON a.video_id=b.video_id
WHERE year(start_time)='2021'
GROUP BY b.video_id
ORDER BY avg_comp_play_rate desc