select p.cid, count(*) pv, round(sum(timestampdiff(minute,start_time,end_time)),3) time_len from course_info_tb c right join play_record_tb p on c.cid=p.cid #where timestampdiff(day,date(start_time),release_date)<=7 where datediff(start_time,release_date)<=7 group by cid having avg(score)>=3 order by pv desc,time_len desc limit 3
注意第5行和第6行的区别
要改正的话,应该是where timestampdiff(day,date(start_time),release_date)>=-7
或者where timestampdiff(day,release_date,date(start_time))<=7
时间方向 | 计算
(方向反,可能包含发布前的数据) | 计算
(方向正确,仅统计发布后) |
时间精度 |
截断时分秒,可能错误包含 / 排除边界时间 | 自动忽略时分秒,直接按日期差判断,逻辑更简洁 |
需求匹配度 | 因方向和截断问题,无法精准匹配 “发布后一周内(≤7 天)” 的需求 | 直接对应 “播放时间 - 发布时间 ≤7 天”,完全匹配需求 |

京公网安备 11010502036488号