我使用以下查询来尝试拉出员工花在每项任务上的时间......
select userid, workclassid,
convert(varchar(6), datediff(second,min(whsworkline.workclosedutcdatetime), max(whsworkline.workclosedutcdatetime))/3600) + ':' +
Right ('0' + convert(varchar(2), (datediff(second,min(whsworkline.workclosedutcdatetime), max(whsworkline.workclosedutcdatetime)) % 3600)/60),2) + ':' +
Right ('0' + convert(varchar(2), datediff(second,min(whsworkline.workclosedutcdatetime), max(whsworkline.workclosedutcdatetime)) %60),2) as 'Picking Time'
from whsworkline
where WORKclosedUTCDATETIME> '5/29/2018' and workclosedutcdatetime < '5/31/2018' and whsworkline.workclosedutcdatetime > '1/1/2001'
Group by userid, workclassid
Order by userid
导致以下数据......
`userid workclassid Picking Time
JIT 33:05:34
SO PICK 0:00:00
MM 8:56:44
alexander. MM 0:00:00
alexander. JIT 29:20:09
alteriq.jo PA-STAGE 31:32:23
alteriq.jo PO_REC 0:00:00
antione.po MM 3:57:48
antione.po JIT 2:57:24
brandon.fe SO PICK 24:09:50
brandon.fe MM 7:43:13
brandon.fe JIT 0:40:14
carl.barto JIT 30:40:34
carl.barto PA-FINAL 19:19:39
carl.barto PA-STAGE 1:13:51
carl.barto MM 6:24:28
chris.gran PACKING 0:08:44
chris.gran STAGE 0:08:50
chris.thom PA-STAGE 23:12:40
chris.thom PA-FINAL 32:47:41
cynthia.yo SO PICK 30:36:09
deauntrey. MM 0:33:01
deauntrey. FG 0:09:09
deshawn.wr SO PICK 24:37:13
deshawn.wr MM 27:35:29
deshawn.wr JIT 3:09:15
Devron.gra SO PICK 28:33:30
edward.coo CycCnt 0:25:40
Elease.wil SO PICK 27:46:23
everlena.h SO PICK 31:20:36
Frankie.mo PA-STAGE 33:10:26
frankie.mo PO_REC 0:00:00
Frankie.mo PA-FINAL 33:22:11
franklin.w JIT 3:54:12
franklin.w PA-STAGE 1:56:04
franklin.w PA-FINAL 4:50:59
harry.gran PA-STAGE 31:40:41
harry.gran PA-FINAL 24:53:10
IT 35:52:37
jalisa.whi SO PICK 31:24:26
james.smoa SO PICK 31:18:40
jaquan.har SO PICK 4:45:02
jermany.ca CycCnt 24:05:26
john.dobso CycCnt 2:15:52
johnny.bus JIT 29:56:52
johnny.bus MM 6:17:14
johnny.bus PA-FINAL 0:09:20
johnny.bus PA-STAGE 0:00:15
Josee.nett SO PICK 28:45:47
Karen.holm SO PICK 25:19:53
keandrea.m SO PICK 30:44:53
lacannin.r MM 0:03:02
lacannin.r SO PICK 27:26:03
lenard.loa SO PICK 2:50:01
lenard.loa MM 28:30:14
lenard.loa JIT 25:54:28
marquis.ma SO PICK 30:55:29
marzetta.g CycCnt 31:11:31
matthew.pa SO PICK 31:19:35
michael.kn PACKING 0:00:09
michael.kn SO PICK 0:00:03
myeisha.mi SO PICK 30:48:39
nathaniel. MM 0:04:13
nathaniel. SO PICK 2:55:35
odell.may MM 26:12:37
odell.may JIT 1:35:49
odell.may SO PICK 24:16:35
oveta.solo SO PICK 25:58:15
paige.walt SO PICK 28:48:27
pamela.fen SO PICK 0:00:00
picker.2 SO PICK 28:30:22
reatha.jen SO PICK 30:10:21
reginald.b CycCnt 32:27:43
Sandra.sco SO PICK 25:51:30
Savannah.g SO PICK 28:48:05
Sharyll.bl CycCnt 30:49:02
sherman.wi SO PICK 31:18:02
sherwin.jo SO PICK 29:00:37
sherwin.jo JIT 0:00:19
shydon.Alb JIT 25:56:35
shydon.Alb MM 28:33:42
stephen.br SO PICK 28:44:30
tewon.thom MM 0:00:00
theaurthus JIT 1:22:08
todd.grant SO PICK 6:55:53
tyrone.mou SO PICK 28:36:53
willie.car JIT 2:00:50
willie.car MM 28:35:34
Willie.dav SO PICK 6:55:38
zakira.wat SO PICK 30:41:17
`
我正在尝试用这些数据解决3个不同的问题。
1a)显然这是一个24小时的时间,并且不可能在一个任务上积累超过24小时,所以我确定我的约会部分存在根本性的错误。
1b)我们的员工一直在任务之间跳转,这是workclassid,所以如果我计算每个班级的第一个和最后一个时间戳之间的约会,并且他们在工作班之间来回走动,那么数据将会出现超过24小时。我试图通过类中的个别作品来计算时间然后对数据求和,但没有成功。2)当我得到数据的那部分时,我需要能够转动数据,这样我就可以每天为每位员工提取总数。这样的事情就是我想要的......
Employee WorkClassID Mon Tues Wed ...
alexander. mm 0:00:00 0:23:09
alexander. jit 29:20:09 0:00:00
alteriq.jo pa-stage 31:32:23 0:01:23
等等。 (星期二那里的数据是由于我没有找到正确拉扯一天的方法而得到的数据,我还没有能够拉到第二天。)但是这就是我想要让所有东西看起来的方式。
我已经对枢轴功能进行了大量研究,但是我无法让它工作,我不知道是不是因为我的问题1a和1b或者是什么。我试图只发布我可以至少部分工作的部分,但如果有人需要看看我如何做其他部分,我当然可以发布这些部分。
我也尝试为问题2创建一个函数,但是我们的数据库安全性阻止我们当前创建新函数。谢谢大家的帮助或指导。小心。
好的Jarl,这是我使用的查询(我只提取了两次发货的数据,因为我的帖子中的字符用尽了)
select *
from whsworkline
where (shipmentid='SH-000146504' or shipmentid='SH-000144368')
order by workid, linenum
这是结果数据......
WORKID LINENUM WORKSTATUS WORKTYPE WMSLOCATIONID ITEMID INVENTDIMID QTYREMAIN INVENTQTYREMAIN INVENTQTYWORK UNITID USERID WORKSTOP INVENTTRANSID WORKTYPECUSTOMCODE ASKFORNEWLICENSEPLATE MANDATORY WORKTEMPLATELINERECID WORKCLASSID QTYWORK LOADLINEREFRECID ORDERNUM LOADID SHIPMENTID ISANCHORED SKIPPED ACTUALTIME AVAILPHYSICAL CONTAINERID ESTIMATEDTIME FEFOBATCHID LOCATEDLPID REPLENDEMAND SORTCODE WORKCLOSEDUTCDATETIME WORKCLOSEDUTCDATETIMETZID WORKINPROCESSUTCDATETIME WORKINPROCESSUTCDATETIMETZID ZONEID MODIFIEDDATETIME MODIFIEDBY DATAAREAID RECVERSION PARTITION RECID EXTRAINVENTHANDLINGQTY CREATEDDATETIME CREATEDBY
WK-000458451 1.0000000000000000 4 1 25-15-4-2 25177222002422 DUS1-000021 0.0000000000000000 0.0000000000000000 1.0000000000000000 ea oveta.solo 0 Lot-008210899 0 1 0 SO PICK 1.0000000000000000 5638124347 DUS1-SO-000000284737 LD-000171638 SH-000144368 0 0 23.0000000000000000 0.0000000000000000 0.0000000000000000 0 228420 2018-05-08 00:13:59.000 37001 2018-05-08 00:13:36.000 37001 AISLE25 2018-05-08 00:13:59.000 ovet.sol dus1 1068767787 5637144576 5638710362 0.0000000000000000 2018-05-07 14:26:22.000 $C9DC
WK-000458451 2.0000000000000000 4 2 P1 25177222002422 DUS1-000021 0.0000000000000000 0.0000000000000000 1.0000000000000000 ea oveta.solo 0 Lot-008210899 0 1 5637146259 SO PICK 1.0000000000000000 0 SH-000144368 0 0 25.0000000000000000 0.0000000000000000 0.0000000000000000 0 0 2018-05-08 00:14:24.000 37001 2018-05-08 00:13:59.000 37001 2018-05-08 00:14:24.000 ovet.sol dus1 516812179 5637144576 5638710361 0.0000000000000000 2018-05-07 14:26:22.000 $C9DC
WK-000465259 1.0000000000000000 4 1 43-52-1-1 21181164962430 DUS1-000021 0.0000000000000000 0.0000000000000000 80.0000000000000000 ea lacannin.r 0 Lot-008318480 0 1 0 SO PICK 80.0000000000000000 5638121693 DUS1-SO-000000288083 LD-000173968 SH-000146504 0 0 571.0000000000000000 0.0000000000000000 0.0000000000000000 0 315780 2018-05-11 19:20:43.000 37001 2018-05-11 19:11:12.000 37001 AISLE43 2018-05-11 19:20:43.000 laca.riz dus1 1018644541 5637144576 5638731713 0.0000000000000000 2018-05-11 14:37:32.000 $C9DC
WK-000465259 2.0000000000000000 4 2 L1 21181164962430 DUS1-000021 0.0000000000000000 0.0000000000000000 80.0000000000000000 ea lacannin.r 0 0 0 5637146149 SO PICK 80.0000000000000000 0 DUS1-SO-000000288083 LD-000173968 SH-000146504 0 0 78.0000000000000000 0.0000000000000000 0.0000000000000000 0 0 2018-05-11 19:22:02.000 37001 2018-05-11 19:20:44.000 37001 2018-05-11 19:22:02.000 laca.riz dus1 454248706 5637144576 5638731705 0.0000000000000000 2018-05-11 14:37:32.000 $C9DC
WK-000465259 3.0000000000000000 4 1 L1 21181164962430 DUS1-000021 0.0000000000000000 0.0000000000000000 80.0000000000000000 ea willisee.s 1 0 0 5637146150 STAGE 80.0000000000000000 0 DUS1-SO-000000288083 LD-000173968 SH-000146504 0 0 18.0000000000000000 0.0000000000000000 0.0000000000000000 0 0 2018-05-14 11:14:42.000 37001 2018-05-14 11:14:24.000 37001 2018-05-14 11:14:42.000 will.sma dus1 481987558 5637144576 5638731706 0.0000000000000000 2018-05-11 14:37:32.000 $C9DC
WK-000465259 4.0000000000000000 4 2 S1 21181164962430 DUS1-000021 0.0000000000000000 0.0000000000000000 80.0000000000000000 ea willisee.s 0 0 0 5637146151 STAGE 80.0000000000000000 0 DUS1-SO-000000288083 LD-000173968 SH-000146504 0 0 5.0000000000000000 0.0000000000000000 0.0000000000000000 0 0 2018-05-14 11:14:47.000 37001 2018-05-14 11:14:42.000 37001 2018-05-14 11:14:47.000 will.sma dus1 2056919670 5637144576 5638731707 0.0000000000000000 2018-05-11 14:37:32.000 $C9DC
WK-000465259 5.0000000000000000 4 1 S1 21181164962430 DUS1-000021 0.0000000000000000 0.0000000000000000 80.0000000000000000 ea willisee.s 1 0 0 5637146152 PACKING 80.0000000000000000 0 DUS1-SO-000000288083 LD-000173968 SH-000146504 0 0 12.0000000000000000 0.0000000000000000 0.0000000000000000 0 0 2018-05-14 11:15:08.000 37001 2018-05-14 11:14:56.000 37001 2018-05-14 11:15:08.000 will.sma dus1 1702601158 5637144576 5638731708 0.0000000000000000 2018-05-11 14:37:32.000 $C9DC
WK-000465259 6.0000000000000000 4 2 P1 21181164962430 DUS1-000021 0.0000000000000000 0.0000000000000000 80.0000000000000000 ea willisee.s 0 0 1 5637146153 PACKING 80.0000000000000000 0 DUS1-SO-000000288083 LD-000173968 SH-000146504 0 0 5.0000000000000000 0.0000000000000000 0.0000000000000000 0 0 2018-05-14 11:15:13.000 37001 2018-05-14 11:15:08.000 37001 2018-05-14 11:15:13.000 will.sma dus1 1337585537 5637144576 5638731709 0.0000000000000000 2018-05-11 14:37:32.000 $C9DC
WK-000465306 1.0000000000000000 4 1 37-35-3-2 21198244962430 DUS1-000021 0.0000000000000000 0.0000000000000000 60.0000000000000000 ea lacannin.r 0 Lot-008317719 0 1 0 SO PICK 60.0000000000000000 5638121692 DUS1-SO-000000288083 LD-000173968 SH-000146504 0 0 163.0000000000000000 0.0000000000000000 0.0000000000000000 0 286810 2018-05-11 17:56:26.000 37001 2018-05-11 17:53:43.000 37001 AISLE37 2018-05-11 18:37:01.000 laca.riz dus1 1000251389 5637144576 5638731710 0.0000000000000000 2018-05-11 14:37:32.000 $C9DC
WK-000465306 2.0000000000000000 4 1 52-62-1-2 21198244962430 DUS1-000021 0.0000000000000000 0.0000000000000000 65.0000000000000000 ea lacannin.r 0 Lot-008317719 0 1 0 SO PICK 65.0000000000000000 5638121692 DUS1-SO-000000288083 LD-000173968 SH-000146504 0 0 12.0000000000000000 0.0000000000000000 0.0000000000000000 0 357550 2018-05-11 18:07:29.000 37001 2018-05-11 18:07:17.000 37001 AISLE52 2018-05-11 18:37:01.000 laca.riz dus1 247111420 5637144576 5638731714 0.0000000000000000 2018-05-11 14:37:32.000 $C9DC
WK-000465306 3.0000000000000000 4 1 54-10-1-2 21198244962430 DUS1-000021 0.0000000000000000 0.0000000000000000 95.0000000000000000 ea lacannin.r 0 Lot-008317719 0 1 0 SO PICK 95.0000000000000000 5638121692 DUS1-SO-000000288083 LD-000173968 SH-000146504 0 0 1513.0000000000000000 0.0000000000000000 0.0000000000000000 0 358360 2018-05-11 18:32:42.000 37001 2018-05-11 18:07:29.000 37001 AISLE54 2018-05-11 18:37:01.000 laca.riz dus1 2030720723 5637144576 5638731715 0.0000000000000000 2018-05-11 14:37:32.000 $C9DC
WK-000465306 4.0000000000000000 4 2 L1 DUS1-000021 0.0000000000000000 0.0000000000000000 220.0000000000000000 lacannin.r 0 0 0 5637146149 SO PICK 220.0000000000000000 0 DUS1-SO-000000288083 LD-000173968 SH-000146504 0 0 5.0000000000000000 0.0000000000000000 0.0000000000000000 0 0 2018-05-11 18:37:07.000 37001 2018-05-11 18:37:02.000 37001 2018-05-11 18:37:07.000 laca.riz dus1 1157555216 5637144576 5638728362 0.0000000000000000 2018-05-11 18:37:01.000 laca.riz
WK-000465306 5.0000000000000000 4 1 L1 DUS1-000021 0.0000000000000000 0.0000000000000000 220.0000000000000000 Patrice.sa 1 0 0 5637146150 STAGE 220.0000000000000000 0 DUS1-SO-000000288083 LD-000173968 SH-000146504 0 0 2.0000000000000000 0.0000000000000000 0.0000000000000000 0 0 2018-05-14 15:57:08.000 37001 2018-05-14 15:57:06.000 37001 2018-05-14 15:57:08.000 patr.san dus1 537033034 5637144576 5638728363 0.0000000000000000 2018-05-11 18:37:01.000 laca.riz
WK-000465306 6.0000000000000000 4 2 S1 DUS1-000021 0.0000000000000000 0.0000000000000000 220.0000000000000000 Patrice.sa 0 0 0 5637146151 STAGE 220.0000000000000000 0 DUS1-SO-000000288083 LD-000173968 SH-000146504 0 0 2.0000000000000000 0.0000000000000000 0.0000000000000000 0 0 2018-05-14 15:57:10.000 37001 2018-05-14 15:57:08.000 37001 2018-05-14 15:57:10.000 patr.san dus1 1001369257 5637144576 5638728364 0.0000000000000000 2018-05-11 18:37:01.000 laca.riz
WK-000465306 7.0000000000000000 4 1 S1 DUS1-000021 0.0000000000000000 0.0000000000000000 220.0000000000000000 Patrice.sa 1 0 0 5637146152 PACKING 220.0000000000000000 0 DUS1-SO-000000288083 LD-000173968 SH-000146504 0 0 7.0000000000000000 0.0000000000000000 0.0000000000000000 0 0 2018-05-14 15:57:22.000 37001 2018-05-14 15:57:15.000 37001 2018-05-14 15:57:22.000 patr.san dus1 2001546561 5637144576 5638728365 0.0000000000000000 2018-05-11 18:37:01.000 laca.riz
WK-000465306 8.0000000000000000 4 2 P1 DUS1-000021 0.0000000000000000 0.0000000000000000 220.0000000000000000 Patrice.sa 0 0 1 5637146153 PACKING 220.0000000000000000 0 DUS1-SO-000000288083 LD-000173968 SH-000146504 0 0 3.0000000000000000 0.0000000000000000 0.0000000000000000 0 0 2018-05-14 15:57:25.000 37001 2018-05-14 15:57:22.000 37001 2018-05-14 15:57:25.000 patr.san dus1 389190161 5637144576 5638728366 0.0000000000000000 2018-05-11 18:37:01.000 laca.riz
WK-000465775 1.0000000000000000 4 1 38-21-5-1 21177264962430 DUS1-000021 0.0000000000000000 0.0000000000000000 123.0000000000000000 ea lacannin.r 0 Lot-008318481 0 1 0 SO PICK 123.0000000000000000 5638121694 DUS1-SO-000000288083 LD-000173968 SH-000146504 0 0 108.0000000000000000 0.0000000000000000 0.0000000000000000 0 290490 2018-05-11 18:38:55.000 37001 2018-05-11 18:37:07.000 37001 AISLE38 2018-05-11 19:01:35.000 laca.riz dus1 510896050 5637144576 5638731711 0.0000000000000000 2018-05-11 14:37:32.000 $C9DC
WK-000465775 2.0000000000000000 4 1 38-33-1-2 21177264962430 DUS1-000021 0.0000000000000000 0.0000000000000000 77.0000000000000000 ea lacannin.r 0 Lot-008318481 0 1 0 SO PICK 77.0000000000000000 5638121694 DUS1-SO-000000288083 LD-000173968 SH-000146504 0 0 474.0000000000000000 0.0000000000000000 0.0000000000000000 0 291240 2018-05-11 19:01:31.000 37001 2018-05-11 18:53:37.000 37001 AISLE38 2018-05-11 19:01:35.000 laca.riz dus1 1959286310 5637144576 5638731712 0.0000000000000000 2018-05-11 14:37:32.000 $C9DC
WK-000465775 3.0000000000000000 4 2 L1 DUS1-000021 0.0000000000000000 0.0000000000000000 200.0000000000000000 ea lacannin.r 0 0 0 5637146149 SO PICK 200.0000000000000000 0 DUS1-SO-000000288083 LD-000173968 SH-000146504 0 0 4.0000000000000000 0.0000000000000000 0.0000000000000000 0 0 2018-05-11 19:01:39.000 37001 2018-05-11 19:01:35.000 37001 2018-05-11 19:01:39.000 laca.riz dus1 1816505295 5637144576 5638728370 0.0000000000000000 2018-05-11 19:01:35.000 laca.riz
WK-000465775 4.0000000000000000 4 1 L1 DUS1-000021 0.0000000000000000 0.0000000000000000 200.0000000000000000 ea Patrice.sa 1 0 0 5637146150 STAGE 200.0000000000000000 0 DUS1-SO-000000288083 LD-000173968 SH-000146504 0 0 3.0000000000000000 0.0000000000000000 0.0000000000000000 0 0 2018-05-14 15:56:46.000 37001 2018-05-14 15:56:43.000 37001 2018-05-14 15:56:46.000 patr.san dus1 947174261 5637144576 5638728371 0.0000000000000000 2018-05-11 19:01:35.000 laca.riz
WK-000465775 5.0000000000000000 4 2 S1 DUS1-000021 0.0000000000000000 0.0000000000000000 200.0000000000000000 ea Patrice.sa 0 0 0 5637146151 STAGE 200.0000000000000000 0 DUS1-SO-000000288083 LD-000173968 SH-000146504 0 0 2.0000000000000000 0.0000000000000000 0.0000000000000000 0 0 2018-05-14 15:56:48.000 37001 2018-05-14 15:56:46.000 37001 2018-05-14 15:56:48.000 patr.san dus1 1418466683 5637144576 5638728372 0.0000000000000000 2018-05-11 19:01:35.000 laca.riz
WK-000465775 6.0000000000000000 4 1 S1 DUS1-000021 0.0000000000000000 0.0000000000000000 200.0000000000000000 ea Patrice.sa 1 0 0 5637146152 PACKING 200.0000000000000000 0 DUS1-SO-000000288083 LD-000173968 SH-000146504 0 0 4.0000000000000000 0.0000000000000000 0.0000000000000000 0 0 2018-05-14 15:56:58.000 37001 2018-05-14 15:56:54.000 37001 2018-05-14 15:56:58.000 patr.san dus1 603075108 5637144576 5638728373 0.0000000000000000 2018-05-11 19:01:35.000 laca.riz
WK-000465775 7.0000000000000000 4 2 P1 DUS1-000021 0.0000000000000000 0.0000000000000000 200.0000000000000000 ea Patrice.sa 0 0 1 5637146153 PACKING 200.0000000000000000 0 DUS1-SO-000000288083 LD-000173968 SH-000146504 0 0 2.0000000000000000 0.0000000000000000 0.0000000000000000 0 0 2018-05-14 15:57:00.000 37001 2018-05-14 15:56:58.000 37001 2018-05-14 15:57:00.000 patr.san dus1 1082386301 5637144576 5638728374 0.0000000000000000 2018-05-11 19:01:35.000 laca.riz