select a.course_id,course_name,count(distinct user_id) online_num

from course_tb a

left join attend_tb b

on a.course_id=b.course_id

where time(in_datetime)<='19:00:00' and time(out_datetime)>="19:00:00"

group by a.course_id,course_name order by a.course_id;**