select  course_name,
        round(avg(TIMESTAMPDIFF(minute,in_datetime,out_datetime)),2) as avg_len
from course_tb right join attend_tb using(course_id)
GROUP BY course_name
order by avg_len DESC