select course_id, course_name, count(*) from attend_tb a left join course_tb b using(course_id) where time(in_datetime) <= "19:00:00" and time(out_datetime) >="19:00:00" group by course_id,course_name order by course_id
只有满足在7点前或者7点整进入,在7点或者7点后退出的记录才能算7点的在线人群,然后使用group by相当于做去重操作。