熟练掌握时间戳函数即可,有date_format,timestampdiff,timestampadd

select cou.course_id,course_name,count(distinct user_id) as cnt
from course_tb cou right join attend_tb att using(course_id)
where date_format(in_datetime,"%Y-%m-%d")=date_format(course_datetime,"%Y-%m-%d")
      and date_format(in_datetime,"%T")<="19:00:00"
      and date_format(out_datetime,"%T")>"19:00:00"
GROUP BY cou.course_id