select b.course_id,course_name, round(count(distinct(case when timestampdiff(minute,in_datetime,out_datetime)>=10 then b.user_id else null end ))*100/count(distinct (case when if_sign = 1 then b.user_id else null end)),2) as attend_rate from course_tb c right join behavior_tb b on c.course_id=b.course_id left join attend_tb a on b.user_id=a.user_id and b.course_id=a.course_id group by b.course_id,course_name order by b.course_id