我回到了外面的标题,才注意到,是得出席10分钟及以上,这个条件题干里面没写
select a.course_id,
a.course_name,
round((b.cnt/a.sign)*100,2) `attend_rate(%)`
from (select a.course_id , b.course_name , sum(if_sign) sign
from behavior_tb a
left join course_tb b
on a.course_id = b.course_id
group by a.course_id,b.course_name) a
left join (select course_id , count(distinct user_id) cnt
from attend_tb
where TIMESTAMPDIFF(minute,in_datetime,out_datetime) >= 10
group by course_id) b
on a.course_id = b.course_id
order by a.course_id