题解 | #平均播放进度大于60%的视频类别#
平均播放进度大于60%的视频类别
https://www.nowcoder.com/practice/c60242566ad94bc29959de0cdc6d95ef
不知道理解是否正确
思路:找到每条播放记录的播放进度:(结束时间-开始时间)/视频时长
难点及易错点:
1:(结束时间-开始时间)>视频时长的均按100%处理
2:%号是字符串,无法进行计算,故应该先条件选出大于60%后使用concat串起来
3:由于where只能在原有数据进行筛选,故需要在大致数据出来后先封装在提取条件
with playprocess as( select b.tag, round( avg( if( timestampdiff(second,a.start_time,a.end_time)>=b.duration,100, timestampdiff(second,a.start_time,a.end_time)/b.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 b.tag order by avg_play_progress desc) select tag, concat(avg_play_progress,'%') as avg_play_progress from playprocess where avg_play_progress > 60