select tag,concat(cast(avg_play_progress*100 as decimal(5,2)),'%') as avg_play_progress from (
select tag,
cast(avg(if(timestampdiff(second,start_time,end_time)>=duration,1,timestampdiff(second,start_time,end_time)/duration)) as decimal(10,4)) as avg_play_progress
from tb_user_video_log tuvl
left join 
tb_video_info tvi on tuvl.video_id = tvi.video_id
group by tag
order by avg_play_progress desc ) a
where avg_play_progress>0.6;

难点:

1、首先是计算的每类视频的平均播放率,故求得的每个值还要想着求平均值;

2、最后结果要求的是百分比结果,若直接转换为百分比,确实是能出结果的,但又要求大于60%,故对算出的结果不能全部要,还要进行一次判定,所以在这计算的时候,需要在最后转换为百分比函数,而在前面直接通过数值去计算;

3、在最后再转换为百分比数,前面是小数,而如果前面的数精确度确定,而后面的数值精确度是有问题的,解决办法:在第一次计算结果时不给出精确度,在第二次计算时再给出精确度(我这没改,因为最开始没想到需要筛选,然后后面就没有改精确度,而是增加了精确位数,在后面计算时,又重新规定精确度,麻烦了。)。