题解 | #各个视频的平均完播率#

各个视频的平均完播率

http://www.nowcoder.com/practice/96263162f69a48df9d84a93c71045753

思路简单,先算出每个视频所观看的长度

select tu.video_id,TIMESTAMPDIFF(second,tu.start_time,tu.end_time) from tb_user_video_log tu;

再关联另外一个表,过滤出2021的数据,并同时取到另外一个表的时长字段(duration)信息

select tu.video_id, TIMESTAMPDIFF(second,tu.start_time,tu.end_time) space, tv.duration 
from tb_user_video_log tu
join tb_video_info tv
on tu.video_id = tv.video_id
where DATE_FORMAT(tu.start_time,"%Y") = '2021';

将上面嵌套称为子查询,通过case when的方式来计算出对应的完播率

select 
    t.video_id
    ,round(ifnull(sum(case when t.space >= t.duration then 1 end),0) / count(1), 3) avg_comp_play_rate
from 
(select tu.video_id, TIMESTAMPDIFF(second,tu.start_time,tu.end_time) space, tv.duration 
from tb_user_video_log tu
join tb_video_info tv
on tu.video_id = tv.video_id
where DATE_FORMAT(tu.start_time,"%Y") = '2021') t
group by t.video_id
order by avg_comp_play_rate desc
全部评论

相关推荐

Twilight_m...:经典我朋友XXXX起手,这是那种经典的不知道目前行情搁那儿胡编乱造瞎指导的中年人,不用理这种**
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务