题解 | #各个视频的平均完播率#
各个视频的平均完播率
http://www.nowcoder.com/practice/96263162f69a48df9d84a93c71045753
步骤1:统计播放每个视频的id的出现的个数select video_id,count() as num_1 from tb_user_video_log group by video_id 步骤2:统计2021年每个视频id播放完成的个数select a.video_id,count() as num from tb_user_video_log a join tb_video_info b on a.video_id=b.video_id where TIMESTAMPDIFF(SECOND,a.start_time,a.end_time)>=b.duration and year(a.start_time)=2021 group by a.video_id中使用函数TIMESTAMPDIFF求两个时间之间相差的秒数,播放视频的时间为2021年year(a.start_time)=2021 步骤3:将步骤1和2表left join ,且用函数求出完成率,保留三位小数round(ifnull(c.num,0)/d.num_1,3);