①两表连接,先用timestampdiff/duration算出每条播放记录的播放进度,此时形成表tb1(注意:播放时长>duration时完成率也是100%,不能大于100%,要用if做个判断)。
②对tb1子查询,根据tag分组、筛选、排序即可。(注意:数字转换为百分数可以用concat)
select tag, concat(round(avg(play_progress)*100,2),'%') as avg_play_progress
from
(
select tag, 
if(timestampdiff(second,start_time,end_time)/duration>1,1,timestampdiff(second,start_time,end_time)/duration) as play_progress
from tb_user_video_log left join tb_video_info using(video_id)
) as tb1
group by tag
having avg(play_progress)>0.6
order by avg_play_progress desc