select
cid,
count(*) as pv,
floor(sum(tl)) as time_len
from
(
select
cid,
timestampdiff(second, start_time, end_time) / 60 as tl
from
play_record_tb
join course_info_tb using (cid)
where
date(start_time) < release_date + 7
) as t
where
cid in (
select
cid
from
play_record_tb
group by
cid
having
avg(score) >= 3
)
group by cid
order by pv DESC,time_len DESC
limit 3 ;
答案其实是错的,播放时长的展示单位可以是分钟甚至也可以是小时,但是统计精度明明可以精确到秒,它却在timestampdiff函数中直接用minute进行统计,这其实是会导致结果产生明显误差的,想象一下A视频的用户都是看到59秒关闭,而B视频的用户都是看到1秒关闭,两者播放次数相同,实际播放时间也相同,但是按照答案的算法就会出现B用户排名高于A视频的情况。我这里无奈为了过题,强行加了floor函数



京公网安备 11010502036488号