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

各个视频的平均完播率

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

相关推荐

点赞 评论 收藏
分享
05-26 10:24
门头沟学院 Java
qq乃乃好喝到咩噗茶:其实是对的,线上面试容易被人当野怪刷了
找工作时遇到的神仙HR
点赞 评论 收藏
分享
评论
5
1
分享

创作者周榜

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