在SQL中创建一个小时的运行总数,但仅使用工作时间

发布于 2025-01-26 01:08:40 字数 2273 浏览 3 评论 0原文

这可能是一个奇怪的问题...但是会尝试解释我能做到的最好的……

顺便说一句:没有机会通过存储过程实施...只能在SQL查询中进行...但是,如果唯一的话选项是sp,然后我必须适应...

我有一个带有以下元素的表:

运行工作按位位置traveltimenumequiptot_time
no991开始
no992客户111218
no993客户2181188
no994客户32293744
no995客户434324

我需要通过计算另一行的时间来添加运行日期和小时,但是这很重要,请考虑工作时间(从9:00起)到13:00和从14:00到18:00(以美国格式:从上午9点到下午1点,下午2点至下午6点)...例如...考虑我的开始日期和时间将是10/5月/2022 9:00:

运行工作界位置旅行时间numequiptot_time日期时间
991开始10/05/229:00
NO992客户11121810/05/2210:52
NO99 NO993客户218118810/05/2211:18
No994客户3229374410/05/2214:08
NO995客户43432412/05/2210: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 :

RUNWORKORDERLOCATIONTRAVELTIMENUMEQUIPTOT_TIME
NO991Start
NO992Customer 111218
NO993Customer 2181188
NO994Customer 32293744
NO995Customer 434324

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 :

RUNWORKORDERLOCATIONTRAVELTIMENUMEQUIPTOT_TIMEDATETIME
NO991Start10/05/229:00
NO992Customer 11121810/05/2210:52
NO993Customer 218118810/05/2211:18
NO994Customer 3229374410/05/2214:08
NO995Customer 43432412/05/2210: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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文