题解 | #平均播放进度大于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函数