在SQL中创建一个小时的运行总数,但仅使用工作时间
这可能是一个奇怪的问题...但是会尝试解释我能做到的最好的……
顺便说一句:没有机会通过存储过程实施...只能在SQL查询中进行...但是,如果唯一的话选项是sp,然后我必须适应...
我有一个带有以下元素的表:
运行 | 工作 | 按位位置 | traveltime | numequip | tot_time |
---|---|---|---|---|---|
no99 | 1 | 开始 | |||
no99 | 2 | 客户1 | 112 | 1 | 8 |
no99 | 3 | 客户2 | 18 | 11 | 88 |
no99 | 4 | 客户3 | 22 | 93 | 744 |
no99 | 5 | 客户4 | 34 | 3 | 24 |
我需要通过计算另一行的时间来添加运行日期和小时,但是这很重要,请考虑工作时间(从9:00起)到13:00和从14:00到18:00(以美国格式:从上午9点到下午1点,下午2点至下午6点)...例如...考虑我的开始日期和时间将是10/5月/2022 9:00:
运行 | 工作界 | 位置 | 旅行 | 时间numequip | tot_time | 日期 | 时间 |
---|---|---|---|---|---|---|---|
99 | 1 | 开始 | 10/05/22 | 9:00 | |||
NO99 | 2 | 客户1 | 112 | 1 | 8 | 10/05/22 | 10:52 |
NO99 NO99 | 3 | 客户2 | 18 | 11 | 88 | 10/05/22 | 11:18 |
No99 | 4 | 客户3 | 22 | 93 | 744 | 10/05/22 | 14:08 |
NO99 | 5 | 客户4 | 34 | 3 | 24 | 12/05/22 | 10:06 |
通过计算估计的客户旅行时间来实现此结果(旅行时间) ),并且还添加了在维护上花费的时间(TOT_TIME是设备的数量(Numequip),而每个设备8分钟)……由于客户3将有744分钟(12 h和58分钟)在维护中...这些分钟将在3天之前产生,结果应如下所示...
在以下查询中,我几乎可以产生所需的效果...但不能仅考虑工作时间...时间是连续的...
Select
RUN,WORKORDER,LOCATION,TRAVELTIME,
DateAdd(mi,temprunningtime-TOT_TIME,'9:00') As TIME,
NUMEQUIP,NUMEQUIP*8 AS TOT_TIME,sum(MYTABLE.TRAVELTIME +
MYTABLE.TOT_TIME) OVER (ORDER BY MYTABLE.ORDER) AS temprunningtime
FROM MYTABLE
随着此查询(略有更改),我有一个运行时间,但没有考虑到13:00-14:00停止和18:00-9:00停止
...有点令人困惑,但是对此的任何iDeias都将不胜感激...我会尽力解释我可以...
This might be a strange question... but will try to explain the best i can ...
BTW : There is no chance in implementing through Stored Procedures... it should be made in SQL Query only ... But if the only option is SP, then i have to adapt to that ...
I have a table with the following elements :
RUN | WORKORDER | LOCATION | TRAVELTIME | NUMEQUIP | TOT_TIME |
---|---|---|---|---|---|
NO99 | 1 | Start | |||
NO99 | 2 | Customer 1 | 112 | 1 | 8 |
NO99 | 3 | Customer 2 | 18 | 11 | 88 |
NO99 | 4 | Customer 3 | 22 | 93 | 744 |
NO99 | 5 | Customer 4 | 34 | 3 | 24 |
I need to add a running DATE and HOUR by calculating the amount of time it takes from one line tho another BUT, and this is important, to take into consideration working hours ( from 9:00 to 13:00 and from 14:00 to 18:00 ( in US format : from 9am to 1pm, and 2pm to 6pm)... As example ... considering that my start date and time would be 10/May/2022 9:00 :
RUN | WORKORDER | LOCATION | TRAVELTIME | NUMEQUIP | TOT_TIME | DATE | TIME |
---|---|---|---|---|---|---|---|
NO99 | 1 | Start | 10/05/22 | 9:00 | |||
NO99 | 2 | Customer 1 | 112 | 1 | 8 | 10/05/22 | 10:52 |
NO99 | 3 | Customer 2 | 18 | 11 | 88 | 10/05/22 | 11:18 |
NO99 | 4 | Customer 3 | 22 | 93 | 744 | 10/05/22 | 14:08 |
NO99 | 5 | Customer 4 | 34 | 3 | 24 | 12/05/22 | 10:06 |
This result is achieved by calculating the estimated time to make the trip between customers (TRAVELTIME), and after arriving is also added the time spent on maintenance (TOT_TIME that is Number of Equipments (NUMEQUIP) vs 8 minutes per equipment)... By this, and since customer 3 will have 744 minutes (12 h and 58 minutes) in maintenance... and those minutes will spawn through 3 days, the result should be as shown...
With the following query i can have almost the desired effect... but cannot take into account only work hours ... and all time is continuous...
Select
RUN,WORKORDER,LOCATION,TRAVELTIME,
DateAdd(mi,temprunningtime-TOT_TIME,'9:00') As TIME,
NUMEQUIP,NUMEQUIP*8 AS TOT_TIME,sum(MYTABLE.TRAVELTIME +
MYTABLE.TOT_TIME) OVER (ORDER BY MYTABLE.ORDER) AS temprunningtime
FROM MYTABLE
With this query (slightly altered) i get an running TIME, but does not take into account the 13:00-14:00 stop, and the 18:00-9:00 stop...
It might be a bit confusing but any ideias on this would be very appreciated... and i will try to explain anyway i can...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论