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

各个视频的平均完播率

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

使用sum+ case when函数能就能解决,不过如果是count 配合case when比较容易出错

select user.video_id,
    round(sum(case when (end_time-start_time)>=duration then 1
             else 0 end )/count(*),3) as avg_comp_play_rate
from tb_user_video_log user join tb_video_info vid
on user.video_id=vid.video_id
where year(start_time)=2021
group by user.video_id 
order by avg_comp_play_rate desc
全部评论
case when timestampdiff(minute,start_time,end_time)>=duration then 1 else 0 end,请问为啥加个timestampdiff就会报错啊?是不能和case when 一起用吗?
点赞 回复 分享
发布于 2023-11-16 16:09 北京
select user.video_id, round(count(case when (end_time-start_time)>=duration then 1 else null end )/count(*),3) as avg_comp_play_rate from tb_user_video_log user join tb_video_info vid on user.video_id=vid.video_id where year(end_time)=2021 group by user.video_id order by avg_comp_play_rate desc
点赞 回复 分享
发布于 2023-04-03 14:38 广东
为什么用count(case when)不行呢
点赞 回复 分享
发布于 2022-04-04 21:53

相关推荐

11-29 00:55
门头沟学院
区域赛银,邀请赛金,打算十二月打下Java基础、背点八股、写个外卖后去投福建小厂的寒假实习,简历应该怎么写呢?以及福州/和厦门有推荐的小厂吗?
牛客53210502...:简历一页:把区域银,邀请赛金标粗,其他的奖除非凑一页否则没有必要写。或者多页:每个站一行这样都列出来。项目经历看看牛客其他人是怎么写的,写的不好呢。简历打磨好按部就班没问题的
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
5
1
分享

创作者周榜

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