题解 | #平均播放进度大于60%的视频类别#

平均播放进度大于60%的视频类别

https://www.nowcoder.com/practice/c60242566ad94bc29959de0cdc6d95ef?tpId=268&tqId=2285032&ru=%2Fexam%2Fcompany&qru=%2Fta%2Fsql-factory-interview%2Fquestion-ranking&sourceUrl=%2Fexam%2Fcompany

select b.tag,
   concat(round(sum(if(TIMESTAMPDIFF(second,start_time,end_time)>=duration,duration,TIMESTAMPDIFF(second,start_time,end_time)))/sum(duration)*100,2),"%") as avg_play_progress
from tb_user_video_log a
left join tb_video_info b
on a.video_id=b.video_id
group by a.video_id
having avg_play_progress>60
order by avg_play_progress desc
#之前在没改时间戳那里的时候自测运行对了,但是保存就错了,多了一个旅游类的。在计算时我们只需要取second就好,要用到TIMESTAMPDIFF函数

全部评论
concat(round(avg(if(TIMESTAMPDIFF(second,start_time,end_time)>=duration,1,TIMESTAMPDIFF(second,start_time,end_time)/duration))*100,2),"%") as avg_play_progress#这样也可以
点赞 回复 分享
发布于 2023-03-30 22:56 广东
concat(round(avg( case when TIMESTAMPDIFF(second,start_time,end_time)>=duration then 1 else TIMESTAMPDIFF(second,start_time,end_time)/duration end)*100,2),"%")as avg_play_progress #还可以用case when 函数(当复习了)
点赞 回复 分享
发布于 2023-03-30 23:05 广东

相关推荐

不愿透露姓名的神秘牛友
02-26 15:46
点赞 评论 收藏
分享
数开小菜鸡:你是我今早见过的最美的牛客女孩......
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务