select t.video_id, ROUND(sum(if((t.end_time-t.start_time)>=t1.duration,1,0))/count(start_time),3) as avg_comp_play_rate from tb_user_video_log t left join tb_video_info t1 on t.video_id=t1.video_id where year(t.start_time)='2021' group by t.video_id order by avg_comp_play_rate desc;
解题思路:①、考察多表结合。
②、视频完播率的计算方法。
第1步:先计算完成播放次数。sum(if((t.end_time-t.start_time)>=t1.duration,1,0
第2步:计算总播放次数。count(start_time)
第3步:保存三位小数。使用ROUND(xx,3)
③、where子条件,筛选2021年,使用year函数
④、order by排序,按照完播率降序,使用desc。