0
我有一个会话活动表与日期。按日期分组按日期分组
sess_actv (id number,actv number,start_date TIMESTAMP(3))
我想白天和我的工作时间(上午8点至下午8点),休息小时(其余)的活动总和。因此,每天我会得到2排,工作时间组和白天小组。
这样的:
select sum(actv), 'work/off hours'
from sess_actv
group by 'work and off hours';
示例表数据
id actv start_date
--- ----- ------------
1 2 21-NOV-13 2.30.02.358 am
2 4 21-NOV-13 10.30.02.358 am
3 7 21-NOV-13 2.30.02.358 pm
4 1 21-NOV-13 10.30.02.358 PM
5 7 22-NOV-13 2.30.02.358 pm
6 1 22-NOV-13 10.30.02.358 PM
查询应该返回:
date sum(actv)
----- ----------
Thursday work hours 11
Thursday off hours 3
friday work hours 7
friday off hours 1
我不知道该怎么做。我设法按天和/或按小时分组,而不是按小时分组。 – Nir
这里有两个问题需要解决。 (1)你如何判断工作或休息时间? Answer ='8到16'之间的'EXTRACT(从start_date开始)“(2)如何确定星期几? Answer ='to_char(start_date,'DAY')'。 – Turophile