select
c.cid,
count(uid) as pv,
sum(timestampdiff(minute,start_time,end_time)) as time_len
from play_record_tb p right join course_info_tb c using(cid)
where
timestampdiff(day,release_date,date(start_time))<=7
group by
c.cid
having
avg(score)>=3
order by
pv desc,time_len desc
limit
3



京公网安备 11010502036488号