题解 | #平均播放进度大于60%的视频类别#
平均播放进度大于60%的视频类别
https://www.nowcoder.com/practice/c60242566ad94bc29959de0cdc6d95ef
select tag, 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 from tb_user_video_log join tb_video_info using (video_id) group by tag having substring_index(avg_play_progress,'%',1) >60 order by avg_play_progress desc
1.注意由于SQL无法直接对%格式的数据进行比较(被定义为字符串数据),所以需要提取百分数中间的数字。也就是无法使用having avg_play_progress>60%,这样的写法是无法识别的,所以只能用sunstring_index把60提取出来。
having substring_index(avg_play_progress,'%',1) >60
2.concat(x,%)这函数是在x后面直接加上%,而不是对x直接进行转化,所以x必须是整数,所以如果中间有avg函数,那么必须对avg的结果*100