题解 | #平均播放进度大于60%的视频类别#
平均播放进度大于60%的视频类别
https://www.nowcoder.com/practice/c60242566ad94bc29959de0cdc6d95ef
先使用tb_user_video_log提取video_id、停留时间(sta_time), ---- timestampdiff(1,2,3):进行时间运算。1:时间的类型,2:大时间,3:小时间。
与tb_video_info进行内连接(inner join) ,-----round(1,2):取舍小数点。1:取小数字段,2:取几位小数。 avg():分组后求平均,跟group by 一起用。
在join后的表中进行列的筛选, -------concat(1,2):合并字符串。1:字符串1,2:字符2。
selects
tag,
concat(avg_play_progress,'%') as avg_play_progress
from (
select
tag,
round(avg(if(sta_time/duration>1,100,sta_time/duration*100)),2) as avg_play_progress
from tb_video_info
inner join
(
select
video_id,
timestampdiff(second,start_time,end_time) as sta_time
from tb_user_video_log
)t1
on t1.video_id = tb_video_info.video_id
group by tag
having avg_play_progress>60
order by avg_play_progress desc
)t2