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

group by c.course_id,course_name

order by c.course_id

分母容易出错,可能出现一个用户多次注册,因此要去重

但是不能直接在主查询中写分母(select course_id,count(distinct user_id ) as cnt from

behavior_tb where if_sign =1 group by course_id)这样主查询本身的group by 和这句子查询中的group by会发生重复,因此把它通过join的形式体现,再在主查询中引用其中的结果