if函数搞定
select b.tag,concat(round(sum(if(timestampdiff(second,start_time,end_time)>duration,duration,timestampdiff(second,start_time,end_time)))/sum(duration)*100,2),'%') as rate from tb_user_video_log a join tb_video_info b on a.video_id=b.video_id group by b.tag having replace(rate,'%','')>60 order by rate desc;