题解 | #各个视频的平均完播率#
各个视频的平均完播率
https://www.nowcoder.com/practice/96263162f69a48df9d84a93c71045753
select video_id AS avg_comp_play_rate, round(avg((end_time - start_time) >= (select vi.duration from tb_video_info vi where vi.video_id = tb_user_video_log.video_id)), 3) AS avg_comp_play_rate from tb_user_video_log where year(start_time) = 2021 group by video_id order by avg_comp_play_rate desc
用子查询来避免联表,我理解一般 tb_video_info 这个表的 video_id 都是有索引的,所以子查询应该会很快