牛客网SQL157

平均播放进度大于60%的视频类别_牛客题霸_牛客网 

select 类别标签,concat(format(平均播放进度*100,2),'%')
from
(
select 类别标签,sum(播放进度)/count(*) 平均播放进度
from
(
  select 视频id,类别标签,播放时长/视频时长 播放进度
  from
  (
     select a.video_id 视频id,b.tag 类别标签,
     case
     when timestampdiff(second, start_time,end_time)>=b.duration
     then b.duration
     else timestampdiff(second, start_time,end_time)
     end 播放时长,
     b.duration 视频时长
     from tb_user_video_log a join tb_video_info b
     on a.video_id=b.video_id
  ) c
) d
group by 类别标签
order by 平均播放进度 desc
) e
where 平均播放进度>0.6

select 类别标签,concat(format(平均播放进度*100,2),'%')
from
(
select 类别标签,sum(播放进度)/count(*) 平均播放进度
from
(
  select 视频id,类别标签,播放时长/视频时长 播放进度
  from
  (
     select a.video_id 视频id,b.tag 类别标签,
     case
     when timestampdiff(second, start_time,end_time)>=b.duration
     then b.duration
     else timestampdiff(second, start_time,end_time)
     end 播放时长,
     b.duration 视频时长
     from tb_user_video_log a join tb_video_info b
     on a.video_id=b.video_id
  ) c
) d
group by 类别标签
order by 平均播放进度 desc
) e
where 平均播放进度>0.6

你可能感兴趣的:(SQL-Oracle,sql)