需要注意某个时间段用户是否在线的判断方式,
如判断7:00-9:00间用户是否在线,有两种情况:
①是进入时间小于7:00:00,并且离开时间大于7:00:00;
②进入时间在7:00-9:00之间。
Select
COUNT(IF((in_time<='7:00:00' and out_time>='7:00:00') OR(in_time BETWEEN '7:00:00' and '9:00:00'), TRUE, NULL)) AS '早通勤',
COUNT(IF((in_time<='18:00:00' and out_time>='18:00:00') OR(in_time BETWEEN '18:00:00' and '20:00:00'), TRUE, NULL)) AS '晚通勤',
COUNT(IF((in_time<='12:00:00' and out_time>='12:00:00') OR(in_time BETWEEN '12:00:00' and '14:00:00'), TRUE, NULL)) AS '午休',
COUNT(IF((in_time<='22:00:00' and out_time>='22:00:00') OR(in_time BETWEEN '22:00:00' and '24:00:00'), TRUE, NULL)) AS '临睡'
From user_view_tb;