题解 | #各个视频的平均完播率#
各个视频的平均完播率
http://www.nowcoder.com/practice/96263162f69a48df9d84a93c71045753
要求:
计算2021年里有播放记录的每个视频的完播率(结果保留三位小数),并按完播率降序排序
思路:
2021年: year(end_time) = 2021 (这里不用year(release_time)是因为题目强调了有播放记录的)
每个视频:Group by video_id (这里的每个视频是指每个发布的视频,不要和观看记录搞混)
完播率:round(avg(if((end_time - start_time) >= duration, 1,0)),3) as complete_rate (if 用来计算完播的视频,avg计算完播率,round保留三位小数)
实现:
select video_id,round(avg(if((end_time - start_time) >= duration, 1,0)),3) as complete_rate
from tb_user_video_log as log
join tb_video_info as info
using (video_id)
WHERE year(end_time) = 2021
GROUP by video_id
order by complete_rate desc