with t1 as ( select video_id,tag, case when timestampdiff(second,start_time,end_time)<duration then timestampdiff(second,start_time,end_time)/duration*100 else 1*100 end as play_progress from tb_video_info join tb_user_video_log using(video_id) ) select tag, concat(round(avg(play_progress),2),'%') as avg_play_progress from t1 group by tag having round(avg(play_progress),2) > 60 order by avg_play_progress desc
关键在于case when 语句 如果不设置条件 就会出现播放率大于100%的情况