题目要求计算各类视频的平均播放进度,将进度大于60%的类别输出
首先将两个表连接起来,将各类视频的计算进度算出来(注意:播放进度=播放时长÷视频时长*100%,当播放时长大于视频时长时,播放进度均记为100%),所以我们用if函数
concat(round((sum(if(timestampdiff(second,start_time,end_time)>duration,duration,timestampdiff(second,start_time,end_time)))/sum(duration))*100,2),'%')
最后直接看代码,不知道咋说了
select tag, concat(round((sum(if(timestampdiff(second,start_time,end_time)>duration,duration,timestampdiff(second,start_time,end_time)))/sum(duration))*100,2),'%') as p
from tb_user_video_log
join tb_video_info
on tb_user_video_log.video_id=tb_video_info.video_id
group by tag
having replace(p,'%','')>60
order by p desc;