select
a.course_id,c.course_name,count(user_id) as online_num
from attend_tb a left join course_tb c
on a.course_id = c.course_id
-- 方式一:使用right函数截取
where right(in_datetime, 8) <= '19:00:00' and right(out_datetime, 8) >= '19:00:00'
-- 方式二:使用date_format格式化取对应时间
# where date_format(in_datetime, '%H:%i') <='19:00' and date_format(out_datetime,'%H:%i') >= '19:00'
group by a.course_id,c.course_name
order by a.course_id

京公网安备 11010502036488号