我想要一个 Oracle 查询来获取时间范围
我的第一个表 TIMINGS
就像
EMPCODE,Att_DATE,IN_TIME,OUT_TIME
我的 MAIN
表是
EMPCODE,DESIGANTION,LACATION ETC.
我的 TIMINGS
表中的数据如下所示:
10101 7/2/2010 7/2/2011 7:08:31 AM 7/2/2011 12:05:31 PM 10101 7/2/2010 7/2/2011 12:58:07 PM 7/2/2011 1:47:36 PM 10101 7/2/2010 7/2/2011 2:17:52 PM 7/2/2011 4:37:23 PM
10102 7/2/2010 7/2/2011 9:44:07 AM 7/2/2011 10:17:53 AM 10102 7/2/2010 7/2/2011 10:25:21 AM 7/2/2011 11:18:28 AM 10102 7/2/2010 7/2/2011 11:28:32 AM 7/2/2011 12:10:31 PM 10102 7/2/2010 7/2/2011 12:35:15 PM 7/2/2011 04:10:04 PM
10103 7/2/2010 7/2/2011 8:56:52 AM 7/2/2011 10:03:39 AM 10103 7/2/2010 7/2/2011 10:10:02 AM 7/2/2011 12:00:07 PM 10103 7/2/2010 7/2/2011 12:22:54 PM 7/2/2011 4:11:03 PM 10103 7/2/2011 7/2/2011 4:51:45 PM 7/2/2011 5:10:45 PM
10104 7/2/2010 7/2/2011 5:12:37 PM 7/2/2011 6:08:23 PM 10104 7/2/2010 7/2/2011 6:20:47 PM 7/3/2011 5:04:33 AM
然后我想将输出显示为
NO OFC 中存在以下时序对中的一个
from-time to-time 00:00:00 7:08 AM 12:10:31PM 12:22:54PM 4:37:23PM 4:51:45PM
My FIRST table TIMINGS
is like
EMPCODE,Att_DATE,IN_TIME,OUT_TIME
My MAIN
table is
EMPCODE,DESIGANTION,LACATION ETC.
The data in my TIMINGS
table is like the following:
10101 7/2/2010 7/2/2011 7:08:31 AM 7/2/2011 12:05:31 PM 10101 7/2/2010 7/2/2011 12:58:07 PM 7/2/2011 1:47:36 PM 10101 7/2/2010 7/2/2011 2:17:52 PM 7/2/2011 4:37:23 PM
10102 7/2/2010 7/2/2011 9:44:07 AM 7/2/2011 10:17:53 AM 10102 7/2/2010 7/2/2011 10:25:21 AM 7/2/2011 11:18:28 AM 10102 7/2/2010 7/2/2011 11:28:32 AM 7/2/2011 12:10:31 PM 10102 7/2/2010 7/2/2011 12:35:15 PM 7/2/2011 04:10:04 PM
10103 7/2/2010 7/2/2011 8:56:52 AM 7/2/2011 10:03:39 AM 10103 7/2/2010 7/2/2011 10:10:02 AM 7/2/2011 12:00:07 PM 10103 7/2/2010 7/2/2011 12:22:54 PM 7/2/2011 4:11:03 PM 10103 7/2/2011 7/2/2011 4:51:45 PM 7/2/2011 5:10:45 PM
10104 7/2/2010 7/2/2011 5:12:37 PM 7/2/2011 6:08:23 PM 10104 7/2/2010 7/2/2011 6:20:47 PM 7/3/2011 5:04:33 AM
then i want to display output as
NO one present in ofc in the following timing pairs
from-time to-time 00:00:00 7:08 AM 12:10:31PM 12:22:54PM 4:37:23PM 4:51:45PM
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样的查询最好是由内而外构建的。
首先,您需要一个仅列出时间和人员变化的结果集。
接下来您需要间隔和运行总计。 Oracle对此有一个机制,请参阅http://www.orafaq.com/node/55了解详情。
这将为您提供人员和间隔。您现在只需要过滤掉一些东西。
Queries like this one are best built inside out.
First you need a result set which just lists times and changes of people.
Next you need intervals and a running total. Oracle has a mechanism for this, see http://www.orafaq.com/node/55 for details.
This will give you people and intervals. You now just need to filter things out.