select course_id,course_name,round(cnt1/cnt2*100,2) as attend_rate
from (
select course_id,
course_name,
count(distinct if(timestampdiff(second,in_datetime,out_datetime)/60>=10,t2.user_id,null)) as cnt1,
count(distinct t1.user_id) as cnt2
from course_tb
left join behavior_tb as t1 using(course_id)
left join attend_tb as t2 using(course_id)
where if_sign=1
group by course_id,course_name
) as t
order by course_id