select course_name, 
       round(avg(len),2) avg_Len
from (select b.course_name, 
             TIMESTAMPDIFF(MINUTE,in_datetime,out_datetime) Len
      from attend_tb a
      left join course_tb b
      on a.course_id = b.course_id) a
group by course_name
order by avg_Len desc