题解 | #平均播放进度大于60%的视频类别#
平均播放进度大于60%的视频类别
https://www.nowcoder.com/practice/c60242566ad94bc29959de0cdc6d95ef
mysql 特有的 可以把聚合字段放在having 和order by后面,的确可以少写点东西,当然判断大于60这里我的写法取巧了,你也可以外面套一层用数字的方式再来比较,可能会更好。
select b.tag, concat(format(avg(case when (unix_timestamp(a.end_time) - unix_timestamp(a.start_time)) >= b.duration then 100 else ((unix_timestamp(a.end_time) - unix_timestamp(a.start_time))/b.duration)*100 end),2),"%" )as avg_play_progress from tb_video_info b join tb_user_video_log a on a.video_id = b.video_id group by b.tag having avg_play_progress > "60.00%" order by avg_play_progress desc