用于计算工作线

时间:2018-05-17 17:57:32

标签: ssms

好了一些提示我要修改这个问题,希望这更清楚一些。

我正在寻找一种查询数据的方法,这样我就可以计算出每种移动类型的行数,还可以计算出货单行的累计时间。这将是我正在寻找的一个例子:

Shipment ID # of SO Picks SO Pick Time # of Stage Lines Stage Time # of Packing lines Packing Time Total time of shipment SH-000026373 1 0:13 (Null) (Null) (Null) (Null) 0:13 SH-000026504 1 0:20 (Null) (Null) (Null) (Null) 0:20 SH-000029530 3 973:17:08 2 22:57:47 2 22:58:55 996:16:16 SH-000038973 13 2:06:01 (Null) (Null) 9 0:02:19 165:00:28 SH-000043978 305 45:42:57 (Null) (Null) (Null) (Null) 45:42:57

目前,我使用此查询从WorkLines表中提取数据......

select shipmentid, itemid, qtywork, wmslocationid, workclassid, workstatus, workclosedutcdatetime, worktype from whsworkline where workclosedutcdatetime > '8/16/2017' and workclosedutcdatetime < '10/15/2017' and (workclassid = 'so pick' or workclassid = 'Stage' or workclassid = 'Packing') order by shipmentid, workclosedutcdatetime

我得到以下数据......

shipmentid itemid qtywork wmslocationid workclassid workstatus workclosedutcdatetime worktype SH-000026373 96001900490000 32 24-20-5-1 SO PICK 4 9/23/2017 15:06:07 1 SH-000026373 96001900490000 32 P1 SO PICK 4 9/23/2017 15:06:20 2 SH-000026504 20182302000422 12 22-50-5-1 SO PICK 4 9/19/2017 10:29:30 1 SH-000026504 20182302000422 12 P1 SO PICK 4 9/19/2017 10:29:50 2 SH-000029530 91039700060095 48 14-4-4-1 SO PICK 4 8/17/2017 2:04:45 1 SH-000029530 91047209251095 14 23-5-7-1 SO PICK 4 8/17/2017 2:10:50 1 SH-000029530 62 L1 SO PICK 4 8/17/2017 2:10:55 2 SH-000029530 91047112251095 184 15-24-2-2 SO PICK 4 9/26/2017 15:21:52 1 SH-000029530 91047112251095 184 L1 SO PICK 4 9/26/2017 15:21:53 2 SH-000029530 91047112251095 184 L1 STAGE 4 9/26/2017 15:21:58 1 SH-000029530 91047112251095 184 S1 STAGE 4 9/26/2017 15:21:59 2 SH-000029530 91047112251095 184 BULKPACK PACKING 4 9/26/2017 15:22:06 2 SH-000029530 91047112251095 184 S1 PACKING 4 9/26/2017 15:22:06 1 SH-000029530 62 L1 STAGE 4 9/27/2017 14:19:40 1 SH-000029530 62 S1 STAGE 4 9/27/2017 14:19:45 2 SH-000029530 62 S1 PACKING 4 9/27/2017 14:20:29 1 SH-000029530 62 P1 PACKING 4 9/27/2017 14:21:01 2 SH-000038973 21198245412430 132 4-14-5-2 SO PICK 4 9/19/2017 19:21:35 1 SH-000038973 21198245412430 18 2-51-4-2 SO PICK 4 9/19/2017 19:27:58 1 SH-000038973 150 L10 SO PICK 4 9/19/2017 19:44:40 2 SH-000038973 21177248812430 72 38-60-1-2 SO PICK 4 9/19/2017 19:54:58 1 SH-000038973 21177248812430 29 39-31-5-1 SO PICK 4 9/19/2017 20:14:53 1 SH-000038973 101 L10 SO PICK 4 9/19/2017 20:15:34 2 SH-000038973 21177248812430 54 38-16-3-2 SO PICK 4 9/19/2017 20:27:39 1 SH-000038973 21177248812430 45 39-23-4-1 SO PICK 4 9/19/2017 20:30:07 1 SH-000038973 99 L10 SO PICK 4 9/19/2017 20:42:18 2 SH-000038973 91019423061625 80 42-55-3-2 SO PICK 4 9/19/2017 20:47:39 1 SH-000038973 91019423061625 80 L10 SO PICK 4 9/19/2017 20:47:49 2 SH-000038973 91019423061625 80 42-58-1-1 SO PICK 4 9/19/2017 21:00:21 1 SH-000038973 91019423061625 80 L10 SO PICK 4 9/19/2017 21:00:34 2 SH-000038973 91019423061625 80 42-61-3-1 SO PICK 4 9/19/2017 21:06:36 1 SH-000038973 91019423061625 80 L10 SO PICK 4 9/19/2017 21:07:05 2 SH-000038973 91019423061625 80 42-62-3-2 SO PICK 4 9/19/2017 21:11:18 1 SH-000038973 91019423061625 80 L10 SO PICK 4 9/19/2017 21:15:26 2 SH-000038973 91019423061625 80 48-6-1-1 SO PICK 4 9/19/2017 21:18:47 1 SH-000038973 91019423061625 80 L10 SO PICK 4 9/19/2017 21:20:52 2 SH-000038973 91019423061625 26 42-39-4-1 SO PICK 4 9/19/2017 21:25:00 1 SH-000038973 91019423061625 24 46-28-4-2 SO PICK 4 9/19/2017 21:27:31 1 SH-000038973 91019423061625 50 L10 SO PICK 4 9/19/2017 21:27:36 2 SH-000038973 91019423061625 50 L10 PACKING 4 9/26/2017 16:19:44 1 SH-000038973 91019423061625 50 P1 PACKING 4 9/26/2017 16:19:48 2 SH-000038973 150 L10 PACKING 4 9/26/2017 16:19:59 1 SH-000038973 150 P1 PACKING 4 9/26/2017 16:20:04 2 SH-000038973 101 L10 PACKING 4 9/26/2017 16:20:14 1 SH-000038973 101 P1 PACKING 4 9/26/2017 16:20:16 2 SH-000038973 99 L10 PACKING 4 9/26/2017 16:20:24 1 SH-000038973 99 P1 PACKING 4 9/26/2017 16:20:27 2 SH-000038973 91019423061625 80 L10 PACKING 4 9/26/2017 16:21:02 1 SH-000038973 91019423061625 80 P1 PACKING 4 9/26/2017 16:21:06 2 SH-000038973 91019423061625 80 L10 PACKING 4 9/26/2017 16:21:17 1 SH-000038973 91019423061625 80 P1 PACKING 4 9/26/2017 16:21:20 2 SH-000038973 91019423061625 80 L10 PACKING 4 9/26/2017 16:21:28 1 SH-000038973 91019423061625 80 P1 PACKING 4 9/26/2017 16:21:38 2 SH-000038973 91019423061625 80 L10 PACKING 4 9/26/2017 16:21:48 1 SH-000038973 91019423061625 80 P1 PACKING 4 9/26/2017 16:21:51 2 SH-000038973 91019423061625 80 L10 PACKING 4 9/26/2017 16:22:00 1 SH-000038973 91019423061625 80 P1 PACKING 4 9/26/2017 16:22:03 2 SH-000043978 91007210490000 72 22-22-4-1 SO PICK 4 9/19/2017 11:46:55 1 SH-000043978 91007210060000 19 22-22-4-2 SO PICK 4 9/19/2017 11:53:15 1 SH-000043978 91007210310000 54 22-23-4-2 SO PICK 4 9/19/2017 11:59:13 1 SH-000043978 USECC250 240 23-47-5-3 SO PICK 4 9/19/2017 12:13:52 1 SH-000043978 91007210060000 53 25-8-4-2 SO PICK 4 9/19/2017 12:17:29 1 SH-000043978 438 P1 SO PICK 4 9/19/2017 12:17:35 2 SH-000043978 91026100426000 27 4-6-2-3 SO PICK 4 9/19/2017 13:03:32 1 SH-000043978 92100022310000 4 DR28 SO PICK 4 9/19/2017 13:13:29 1 SH-000043978 92100022310000 2 DR28 SO PICK 4 9/19/2017 13:14:32 1 SH-000043978 96002000536000 4 DR3 SO PICK 4 9/19/2017 13:17:54 1 SH-000043978 96211040000100 3 DR25 SO PICK 4 9/19/2017 13:20:32 1 SH-000043978 91004923370100 1 DR24 SO PICK 4 9/19/2017 13:22:50 1 SH-000043978 91001533310025 1 18-50-1-2 SO PICK 4 9/19/2017 13:26:34 1 SH-000043978 92009600426000 1 18-33-2-2 SO PICK 4 9/19/2017 13:28:10 1 SH-000043978 91001404060025 3 18-33-1-1 SO PICK 4 9/19/2017 13:30:36 1 SH-000043978 91049924310099 2 18-25-2-1 SO PICK 4 9/19/2017 13:32:11 1 SH-000043978 93007404730000 4 17-2-1-5 SO PICK 4 9/19/2017 13:36:04 1 SH-000043978 20136272000460 1 17-4-4-2 SO PICK 4 9/19/2017 14:09:24 1 SH-000043978 20182232000422 2 17-5-3-3 SO PICK 4 9/19/2017 14:09:59 1 SH-000043978 59989016000625 21 17-6-4-5 SO PICK 4 9/19/2017 14:13:09 1 SH-000043978 21180300101430 1 17-8-1-2 SO PICK 4 9/19/2017 14:13:47 1 SH-000043978 93004616000000 10 17-11-1-1 SO PICK 4 9/19/2017 14:15:58 1 SH-000043978 91028500444005 2 17-11-4-3 SO PICK 4 9/19/2017 14:18:04 1 SH-000043978 91007240310000 15 17-15-4-3 SO PICK 4 9/19/2017 14:22:24 1 SH-000043978 93010200060000 12 17-17-1-1 SO PICK 4 9/19/2017 14:23:39 1 SH-000043978 94034570000001 30 17-21-4-2 SO PICK 4 9/19/2017 14:25:46 1 SH-000043978 25180222002422 1 17-22-4-3 SO PICK 4 9/19/2017 14:26:17 1 SH-000043978 93010300310000 12 17-23-3-1 SO PICK 4 9/19/2017 14:27:59 1 SH-000043978 91008600310000 3 17-24-2-3 SO PICK 4 9/19/2017 14:29:28 1 SH-000043978 91007210370000 24 17-24-2-5 SO PICK 4 9/19/2017 14:31:38 1 SH-000043978 91007210090000 24 17-24-3-2 SO PICK 4 9/19/2017 14:32:36 1 SH-000043978 20164340600460 1 17-29-3-4 SO PICK 4 9/19/2017 14:36:55 1 SH-000043978 91007900090000 4 17-31-1-1 SO PICK 4 9/19/2017 14:39:38 1 SH-000043978 91041926403000 6 17-32-1-2 SO PICK 4 9/19/2017 14:42:16 1 SH-000043978 91015800490000 2 17-37-1-1 SO PICK 4 9/19/2017 14:43:59 1 SH-000043978 98401200000000 3 17-37-4-2 SO PICK 4 9/19/2017 14:44:50 1 SH-000043978 25097282002460 1 17-51-1-2 SO PICK 4 9/19/2017 14:45:23 1 SH-000043978 95003440090300 12 17-52-2-1 SO PICK 4 9/19/2017 14:46:20 1 SH-000043978 91041836403000 2 16-46-2-1 SO PICK 4 9/19/2017 14:48:05 1 SH-000043978 91041918403000 3 16-44-2-2 SO PICK 4 9/19/2017 14:48:40 1 SH-000043978 91042332060000 1 16-41-1-2 SO PICK 4 9/19/2017 14:51:01 1 SH-000043978 91042332426000 1 16-41-1-1 SO PICK 4 9/19/2017 14:51:31 1 SH-000043978 91014900426210 1 16-36-2-1 SO PICK 4 9/19/2017 14:53:26 1 SH-000043978 91005000426000 24 16-35-2-2 SO PICK 4 9/19/2017 14:56:53 1 SH-000043978 91005723426100 2 16-33-2-1 SO PICK 4 9/19/2017 14:59:25 1 SH-000043978 25178354262422 1 16-29-1-2 SO PICK 4 9/19/2017 15:00:25 1 SH-000043978 25138350600422 3 16-28-2-2 SO PICK 4 9/19/2017 15:05:54 1 SH-000043978 277 P1 SO PICK 4 9/19/2017 15:06:15 2 SH-000043978 20182300900422 1 16-16-2-2 SO PICK 4 9/19/2017 15:22:58 1 SH-000043978 25177284262422 1 16-16-1-1 SO PICK 4 9/19/2017 15:23:23 1 SH-000043978 91000410090900 4 16-12-1-1 SO PICK 4 9/19/2017 15:24:31 1 SH-000043978 91010038310145 2 15-11-1-2 SO PICK 4 9/19/2017 15:27:55 1 SH-000043978 92001300536000 3 15-21-2-1 SO PICK 4 9/19/2017 15:30:29 1 SH-000043978 91006223426100 3 15-23-1-2 SO PICK 4 9/19/2017 15:31:55 1 SH-000043978 91015800310000 10 15-24-2-1 SO PICK 4 9/19/2017 15:35:42 1 SH-000043978 91000410426426 4 15-27-2-2 SO PICK 4 9/19/2017 15:43:31 1 SH-000043978 91004020426100 4 15-30-2-1 SO PICK 4 9/19/2017 15:44:58 1 SH-000043978 91004036426100 3 15-31-2-1 SO PICK 4 9/19/2017 15:47:43 1 SH-000043978 91008408426400 4 15-38-1-2 SO PICK 4 9/19/2017 15:51:53 1 SH-000043978 91007900426000 4 15-41-2-2 SO PICK 4 9/19/2017 15:54:22 1 SH-000043978 91028200490005 1 15-42-1-2 SO PICK 4 9/19/2017 15:54:42 1 SH-000043978 20188204262422 2 15-44-1-2 SO PICK 4 9/19/2017 15:55:28 1 SH-000043978 91028200140005 1 15-44-2-1 SO PICK 4 9/19/2017 15:55:53 1 SH-000043978 91007202426099 24 15-46-2-1 SO PICK 4 9/19/2017 15:56:26 1 SH-000043978 91041932310000 3 15-47-1-1 SO PICK 4 9/19/2017 15:57:59 1 SH-000043978 21178290101430 1 15-49-1-1 SO PICK 4 9/19/2017 15:58:28 1 SH-000043978 91041926010000 6 15-49-2-2 SO PICK 4 9/19/2017 16:01:41 1 SH-000043978 91049924536099 2 15-50-1-2 SO PICK 4 9/19/2017 16:11:26 1 SH-000043978 91019423310025 4 15-50-2-1 SO PICK 4 9/19/2017 16:16:39 1 SH-000043978 91042024310000 1 15-50-2-2 SO PICK 4 9/19/2017 16:17:46 1 SH-000043978 91042332010025 6 15-51-1-2 SO PICK 4 9/19/2017 16:20:01 1 SH-000043978 91041918010000 4 15-52-2-1 SO PICK 4 9/19/2017 16:21:22 1 SH-000043978 25097280602460 2 14-2-1-2 SO PICK 4 9/19/2017 16:22:38 1 SH-000043978 91049924060099 4 14-5-1-2 SO PICK 4 9/19/2017 16:24:51 1 SH-000043978 92000900010000 5 13-2-1-2 SO PICK 4 9/19/2017 17:09:53 1 SH-000043978 91041828060000 4 14-16-2-2 SO PICK 4 9/19/2017 17:12:08 1 SH-000043978 91049906310099 2 13-10-1-1 SO PICK 4 9/19/2017 17:13:21 1 SH-000043978 91007202090099 24 14-18-2-1 SO PICK 4 9/19/2017 17:15:17 1 SH-000043978 91049906403099 4 14-19-1-1 SO PICK 4 9/19/2017 17:16:18 1 SH-000043978 143 P1 SO PICK 4 9/19/2017 17:17:32 2 SH-000043978 91026100426000 9 4-6-2-3 SO PICK 4 9/19/2017 17:45:29 1 SH-000043978 91007202010099 12 14-19-2-1 SO PICK 4 9/19/2017 17:47:44 1 SH-000043978 20132400600460 6 14-21-1-1 SO PICK 4 9/19/2017 17:49:34 1 SH-000043978 91001909310000 9 13-17-1-1 SO PICK 4 9/19/2017 17:54:18 1 SH-000043978 96002000010000 2 13-17-1-2 SO PICK 4 9/19/2017 17:59:48 1 SH-000043978 93005100426200 2 14-23-1-1 SO PICK 4 9/19/2017 18:00:54 1 SH-000043978 91049906010099 6 13-19-1-2 SO PICK 4 9/19/2017 18:02:25 1 SH-000043978 91031800060005 2 13-19-2-1 SO PICK 4 9/19/2017 18:05:33 1 SH-000043978 91031800310005 1 13-20-2-1 SO PICK 4 9/19/2017 18:06:35 1 SH-000043978 20142240000460 2 13-22-2-1 SO PICK 4 9/19/2017 18:07:55 1 SH-000043978 91006223490125 2 14-30-2-1 SO PICK 4 9/19/2017 18:10:59 1 SH-000043978 21178230101430 1 14-32-2-2 SO PICK 4 9/19/2017 18:11:30 1 SH-000043978 91007210222000 24 13-29-1-1 SO PICK 4 9/19/2017 18:13:03 1 SH-000043978 91041918060000 12 14-35-2-1 SO PICK 4 9/19/2017 18:17:14 1 SH-000043978 20182260100422 1 14-42-1-1 SO PICK 4 9/19/2017 18:18:43 1 SH-000043978 91034607060099 6 14-42-2-1 SO PICK 4 9/19/2017 18:21:25 1 SH-000043978 91042024490000 1 13-35-1-2 SO PICK 4 9/19/2017 18:23:30 1 SH-000043978 21180304442430 1 14-45-1-2 SO PICK 4 9/19/2017 18:24:10 1 SH-000043978 96002100490000 1 13-37-1-2 SO PICK 4 9/19/2017 18:26:46 1 SH-000043978 96200130000100 1 14-45-2-2 SO PICK 4 9/19/2017 18:28:08 1 SH-000043978 96002000310000 3 13-38-1-1 SO PICK 4 9/19/2017 18:29:32 1 SH-000043978 25181180602422 1 14-46-2-2 SO PICK 4 9/19/2017 18:30:25 1 SH-000043978 91044402426000 6 14-47-2-2 SO PICK 4 9/19/2017 18:31:47 1 SH-000043978 91007520310305 6 14-50-1-1 SO PICK 4 9/19/2017 18:32:39 1 SH-000043978 91034500510005 3 14-51-1-1 SO PICK 4 9/19/2017 18:33:16 1 SH-000043978 91019423426025 2 14-51-1-2 SO PICK 4 9/19/2017 18:33:35 1 SH-000043978 96002000090000 2 13-45-1-2 SO PICK 4 9/19/2017 18:36:22 1 SH-000043978 96002000140000 2 13-48-2-1 SO PICK 4 9/19/2017 18:37:32 1 SH-000043978 91041932010000 3 13-49-1-1 SO PICK 4 9/19/2017 18:39:20 1 SH-000043978 91033052490099 30 13-51-2-2 SO PICK 4 9/19/2017 18:41:32 1 SH-000043978 91015924490100 3 12-50-2-2 SO PICK 4 9/19/2017 18:42:44 1 SH-000043978 10006002000060 1 12-49-2-2 SO PICK 4 9/19/2017 18:42:57 1 SH-000043978 91028500060005 1 12-48-2-1 SO PICK 4 9/19/2017 18:43:46 1 SH-000043978 91041926490000 10 12-47-2-2 SO PICK 4 9/19/2017 18:46:32 1 SH-000043978 20182262000422 1 12-47-2-1 SO PICK 4 9/19/2017 18:46:49 1 SH-000043978 91049906426099 2 12-44-2-2 SO PICK 4 9/19/2017 18:47:56 1 SH-000043978 91001533490025 4 12-44-1-2 SO PICK 4 9/19/2017 18:49:15 1 SH-000043978 25177241702422 2 12-42-2-1 SO PICK 4 9/19/2017 18:51:39 1 SH-000043978 91005720010100 3 12-36-1-1 SO PICK 4 9/19/2017 18:52:34 1 SH-000043978 96200230000100 1 12-33-1-2 SO PICK 4 9/19/2017 18:54:10 1 SH-000043978 91000310310000 9 12-33-1-1 SO PICK 4 9/19/2017 19:02:11 1 SH-000043978 196 P1 SO PICK 4 9/19/2017 19:08:20 2 SH-000043978 91008600370000 2 12-32-2-1 SO PICK 4 9/20/2017 11:33:07 1 SH-000043978 91028200444005 1 12-28-1-2 SO PICK 4 9/20/2017 11:33:51 1 SH-000043978 20136270600460 1 12-24-1-1 SO PICK 4 9/20/2017 11:34:44 1 SH-000043978 91004732010125 1 12-21-1-1 SO PICK 4 9/20/2017 11:35:13 1 SH-000043978 91010038091405 4 12-19-2-1 SO PICK 4 9/20/2017 11:37:11 1 SH-000043978 91001909060000 16 12-12-2-1 SO PICK 4 9/20/2017 11:38:55 1 SH-000043978 21177240101430 2 12-12-1-2 SO PICK 4 9/20/2017 11:39:17 1 SH-000043978 20182302000422 1 12-9-1-2 SO PICK 4 9/20/2017 11:42:11 1 SH-000043978 91034607310099 4 12-8-2-1 SO PICK 4 9/20/2017 11:42:48 1 SH-000043978 91049906060099 4 12-6-2-1 SO PICK 4 9/20/2017 11:43:37 1 SH-000043978 91015800090000 8 12-4-1-2 SO PICK 4 9/20/2017 11:45:00 1 SH-000043978 96002000490000 2 12-3-1-2 SO PICK 4 9/20/2017 11:46:15 1 SH-000043978 96002000060000 4 12-3-1-1 SO PICK 4 9/20/2017 11:47:09 1 SH-000043978 96001900060000 6 12-2-1-1 SO PICK 4 9/20/2017 11:47:31 1 SH-000043978 91033052060099 18 12-1-2-1 SO PICK 4 9/20/2017 11:49:27 1 SH-000043978 91007210426000 24 11-1-1-2 SO PICK 4 9/20/2017 11:50:40 1 SH-000043978 20188324442422 1 11-1-2-1 SO PICK 4 9/20/2017 11:50:58 1 SH-000043978 25181164032422 2 11-7-2-1 SO PICK 4 9/20/2017 11:51:45 1 SH-000043978 91049906090099 3 11-15-1-1 SO PICK 4 9/20/2017 11:52:55 1 SH-000043978 91025054060000 5 11-17-2-1 SO PICK 4 9/20/2017 11:54:24 1 SH-000043978 9200090044000 2 11-20-2-1 SO PICK 4 9/20/2017 11:55:17 1 SH-000043978 91036014060005 2 11-22-1-1 SO PICK 4 9/20/2017 11:55:37 1 SH-000043978 91044404010000 4 11-27-1-1 SO PICK 4 9/20/2017 11:57:22 1 SH-000043978 91027500490100 2 11-27-2-2 SO PICK 4 9/20/2017 12:04:08 1 SH-000043978 25177280902422 3 11-30-1-2 SO PICK 4 9/20/2017 12:06:47 1 SH-000043978 91041918490000 12 11-30-2-1 SO PICK 4 9/20/2017 12:08:46 1 SH-000043978 93007300060000 12 11-32-2-2 SO PICK 4 9/20/2017 12:09:32 1 SH-000043978 25157242002460 1 11-34-1-2 SO PICK 4 9/20/2017 12:09:48 1 SH-000043978 93007300010000 12 11-34-2-1 SO PICK 4 9/20/2017 12:10:58 1 SH-000043978 92009500536000 1 11-35-2-2 SO PICK 4 9/20/2017 12:12:18 1 SH-000043978 91028212010005 1 11-41-1-2 SO PICK 4 9/20/2017 12:13:21 1 SH-000043978 93007400010000 6 11-44-2-1 SO PICK 4 9/20/2017 12:16:05 1 SH-000043978 91013915060000 2 11-45-2-1 SO PICK 4 9/20/2017 12:17:46 1 SH-000043978 91041828490000 3 11-52-2-1 SO PICK 4 9/20/2017 12:20:50 1 SH-000043978 21177344442430 1 10-52-1-1 SO PICK 4 9/20/2017 12:21:19 1 SH-000043978 20188244442422 1 10-51-2-1 SO PICK 4 9/20/2017 12:27:53 1 SH-000043978 25180322002422 1 10-51-1-2 SO PICK 4 9/20/2017 12:28:33 1 SH-000043978 25177300902422 1 10-51-1-1 SO PICK 4 9/20/2017 12:43:20 1 SH-000043978 21308324260430 1 10-47-1-2 SO PICK 4 9/20/2017 12:43:49 1 SH-000043978 20182160000422 3 10-46-2-2 SO PICK 4 9/20/2017 12:44:20 1 SH-000043978 91004732090125 1 10-46-1-2 SO PICK 4 9/20/2017 12:53:41 1 SH-000043978 96600226000000 1 10-45-2-2 SO PICK 4 9/20/2017 12:57:22 1 SH-000043978 91031800090005 1 10-36-2-1 SO PICK 4 9/20/2017 12:57:53 1 SH-000043978 91007202401099 6 10-36-1-2 SO PICK 4 9/20/2017 12:58:10 1 SH-000043978 91019100060000 3 10-35-1-2 SO PICK 4 9/20/2017 12:59:29 1 SH-000043978 91007202213099 16 10-34-1-2 SO PICK 4 9/20/2017 13:00:56 1 SH-000043978 91035311090700 4 10-33-1-1 SO PICK 4 9/20/2017 13:02:35 1 SH-000043978 20182264440422 1 10-31-2-2 SO PICK 4 9/20/2017 13:03:05 1 SH-000043978 96002000541000 2 10-30-2-2 SO PICK 4 9/20/2017 13:04:25 1 SH-000043978 91005000140700 12 10-27-2-1 SO PICK 4 9/20/2017 13:05:02 1 SH-000043978 91015800010000 10 10-21-2-1 SO PICK 4 9/20/2017 13:10:28 1 SH-000043978 96002000426000 2 10-19-2-2 SO PICK 4 9/20/2017 13:16:55 1 SH-000043978 239 P1 SO PICK 4 9/20/2017 13:19:19 2 SH-000043978 20182261700422 3 10-18-2-1 SO PICK 4 9/20/2017 13:34:49 1 SH-000043978 91001402536025 4 10-17-1-2 SO PICK 4 9/20/2017 13:36:00 1 SH-000043978 25180302002422 1 10-9-1-2 SO PICK 4 9/20/2017 13:36:33 1 SH-000043978 25177302002422 3 10-9-1-1 SO PICK 4 9/20/2017 13:37:11 1 SH-000043978 91000310060000 4 10-6-1-2 SO PICK 4 9/20/2017 13:38:20 1 SH-000043978 91042332090025 1 10-4-1-2 SO PICK 4 9/20/2017 14:12:27 1 SH-000043978 91007900310000 8 10-2-1-1 SO PICK 4 9/20/2017 14:13:43 1 SH-000043978 96001900403000 8 9-6-1-1 SO PICK 4 9/20/2017 14:15:14 1 SH-000043978 92009600010000 2 9-18-1-1 SO PICK 4 9/20/2017 14:16:59 1 SH-000043978 20182300600422 8 9-23-1-1 SO PICK 4 9/20/2017 14:26:34 1 SH-000043978 20182260600422 1 9-24-1-1 SO PICK 4 9/20/2017 14:26:52 1 SH-000043978 91014900310210 4 9-27-1-2 SO PICK 4 9/20/2017 14:28:07 1 SH-000043978 25177240902422 4 9-37-1-2 SO PICK 4 9/20/2017 14:29:58 1 SH-000043978 91015800536000 6 9-43-1-1 SO PICK 4 9/20/2017 14:32:21 1 SH-000043978 91001909490000 10 9-45-2-2 SO PICK 4 9/20/2017 14:34:29 1 SH-000043978 91014900490210 12 9-48-2-1 SO PICK 4 9/20/2017 14:42:49 1 SH-000043978 20142240600460 2 9-49-2-2 SO PICK 4 9/20/2017 14:43:04 1 SH-000043978 91041918090000 10 9-51-1-1 SO PICK 4 9/20/2017 14:45:26 1 SH-000043978 91034607010099 12 9-51-2-1 SO PICK 4 9/20/2017 14:48:27 1 SH-000043978 96002000256000 2 8-51-1-2 SO PICK 4 9/20/2017 14:50:27 1 SH-000043978 91004732490100 1 8-49-2-1 SO PICK 4 9/20/2017 14:52:56 1 SH-000043978 96001900426000 4 8-47-1-2 SO PICK 4 9/20/2017 14:53:32 1 SH-000043978 91044401426000 6 8-44-2-1 SO PICK 4 9/20/2017 14:55:18 1 SH-000043978 25177140602422 6 8-42-2-2 SO PICK 4 9/20/2017 14:57:51 1 SH-000043978 96001900213000 4 8-37-1-1 SO PICK 4 9/20/2017 14:58:34 1 SH-000043978 21177280101430 1 8-35-1-1 SO PICK 4 9/20/2017 14:59:37 1 SH-000043978 91005713490100 6 8-30-1-1 SO PICK 4 9/20/2017 15:01:35 1 SH-000043978 92009500060000 4 8-24-1-2 SO PICK 4 9/20/2017 15:04:53 1 SH-000043978 92009600310000 1 8-21-1-1 SO PICK 4 9/20/2017 15:07:35 1 SH-000043978 91005723090100 3 8-20-1-2 SO PICK 4 9/20/2017 15:08:29 1 SH-000043978 141 P1 SO PICK 4 9/20/2017 15:10:09 2 SH-000043978 92009600060000 3 8-16-1-1 SO PICK 4 9/20/2017 15:17:23 1

以下是有关该数据的一些信息要点:   - &#34; WorkType&#34;是Pick(1)还是Put(2)   - &#34; WorkClassID&#34;是货物内的运动类型。     - 我们的一些订单只有一种类型的移动,这意味着它们被拾取并直接从Pickface到Pack Station。     - 我们的其他一些订单有2个和3个移动,这意味着它们被挑选并放到次要处理区域以进行标记。然后他们有另一个动作(舞台)将其从标签区域移动到合并区域。然后进行第三次运动(包装)将其从包装区域移出集合区域。

我觉得应该很容易计算两条线之间的时差(也许可能使用Datediff),这对于只有一条线的货物就足够了。但是,我需要能够计算几个不同的东西,以便从第一个例子中获得所需的结果......

1)我需要知道每次运动中从第一次选择(工作类型1)到最后一次投入(工作类型2)的累计总时间(WorkClassID&#39; s&#34; SO Pick&#34;,& #34;阶段&#34;,&#34;包装&#34;)。  2)我需要知道从第一批货物到最后一批货物的累计时间。并且它不能是为装运计算的所有时间的总和,因为每个&#34; WorkClassID&#34;之间存在显着差距。我需要将这些差距折叠到我的总计时间计算中。

从我的&#34;我正在寻找的例子&#34;回到这些陈述,我试图建立一个能够告诉我的报告......

1)该客户的订单需要X个时间来挑选  2)该客户的订单需要X个标签时间  3)该客户的订单在仓库中花费X时间

我非常感谢这里的帮助,谢谢你的时间。

好的,在Daniel的一堆帮助之后,这就是我目前使用SQL查询的地方。不得不改变一些事情,但他的基本想法很棒......

`选择whsworkline.shipmentid作为&#39;发货ID&#39;,whsworkline.ordernum作为&#39; Order Num&#39;,salestable.custaccount&#39; Customer Acct&#39;,whswaveline.waveid as &#39; Wave ID&#39;,whswavetable.wavetemplatename as&#39; Wave Template&#39;,  count(如果whsworkline.workclassid =&#39;那么选择&#39;以及whsworkline.worktype =&#39; 1&#39;然后whsworkline.itemid else null结束)作为&#39; Pick Lines&#39;,< / p>

转换(varchar,datediff(第二,min)(当whsworkline.workclassid =&#39时的情况;所以选择&#39;然后whsworkline.WORKINPROCESSUTCDATETIME其他为null结束),max(whsworkline.workclassid =&#39; so的情况)选择&#39;然后whsworkline.workclosedutcdatetime else null end))/(60 * 60 * 24))+&#39;:&#39; +  convert(varchar,dateadd(s,datediff(second,min)(当whsworkline.workclassid =&#39;因此选择&#39;然后whsworkline.WORKINPROCESSUTCDATETIME其他为null结束时),max(whsworkline.workclassid =&#39;所以选择&#39;然后whsworkline.workclosedutcdatetime else null结束)),转换(datetime2,&#39; 0001-01-01&#39;)),108)作为&#39; Picking Time&#39;,

计数(当whsworkline.workclassid喜欢&#39;%包装%&#39;和whsworkline.worktype =&#39; 1&#39;然后whsworkline.itemid其他为空结束时)作为&#39;托盘标签& #39; ,

convert(varchar,datediff(second,max)(当whsworkline.workclassid喜欢&#39;%所以选择%&#39;以及whsworkline.worktype =&#39; 2&#39;然后whsworkline.WORKCLOSEDUTCDATETIME else null结束),max(whsworkline.workclassid喜欢&#39;%packing%&#39;以及whsworkline.worktype =&#39; 2&#39;然后whsworkline.workclosedutcdatetime else null结束时的情况))/(60 * 60 * 24))+&#39;:&#39; +   convert(varchar,dateadd(s,datediff(second,max)(当whsworkline.workclassid喜欢&#39;%所以选择%&#39;和whsworkline.worktype =&#39; 2&#39;然后whsworkline.WORKCLOSEDUTCDATETIME else null end),max(当whsworkline.workclassid喜欢&#39;%packing%&#39;以及whsworkline.worktype =&#39; 2&#39;然后whsworkline.workclosedutcdatetime else null结束时)),convert(datetime2, &#39; 0001-01-01&#39;)),108)&#39;标记时间&#39;,

转换(varchar,datediff(SECOND,min(whsworkline.WORKINPROCESSUTCDATETIME),max(whsworkline.workclosedutcdatetime))/(60 * 60 * 24))+&#39;:&#39; +    convert(varchar,dateadd(s,datediff(SECOND,min(whsworkline.WORKINPROCESSUTCDATETIME),max(whsworkline.workclosedutcdatetime)),convert(datetime2,&#39; 0001-01-01&#39;)),108)&# 39; WHS工作时间&#39;,

convert(varchar,datediff(SECOND,min(whsworkline.createddatetime),max(whsworkline.workclosedutcdatetime))/(60 * 60 * 24))+&#39;:&#39; +    convert(varchar,dateadd(s,datediff(SECOND,min(whsworkline.createddatetime),max(whsworkline.workclosedutcdatetime)),convert(datetime2,&#39; 0001-01-01&#39;)),108)&# 39;总WHS时间&#39;

来自whsworkline    加入salestable    在whsworkline.ordernum = salestable.salesid    加入whswaveline    在whsworkline.shipmentid = whswaveline.shipmentid    加入whswavetable    在whswaveline.waveid = whswavetable.waveid    其中whsworkline.workclosedutcdatetime&gt; &#39; 8/16/2017年&#39;和whsworkline.workclosedutcdatetime&lt; &#39 10 /二千零十七分之十五&#39;和 (whsworkline.workclassid =&#39;所以选择&#39;或whsworkline.workclassid =&#39; Stage&#39;或whsworkline.workclassid =&#39; Packing&#39;) group by whsworkline.shipmentid,whsworkline.ordernum,salestable.custaccount,whswaveline.waveid,whswavetable.wavetemplatename`

他和我仍在努力解决一些问题。

1 个答案:

答案 0 :(得分:0)

select shipmentid, itemid, qtywork, wmslocationid, workclassid, workstatus, workclosedutcdatetime, worktype into #temp
from whsworkline
where workclosedutcdatetime > '9/17/2017' and workclosedutcdatetime < '9/24/2017' and workclassid = 'so pick'
order by shipmentid, workclosedutcdatetime

这对你有什么用?时间只是几个小时,但如果可以的话可以调整。假设#temp是原始查询的结果,我们从那里开始工作:

        select shipmentid,  count(distinct case when  workclassid='so' and worktype=1 then null else itemid end ) [# of SO Picks], 

convert(varchar, datediff(s, min(case when workclassid = 'so' then workclosedutcdatetime else null end), 
max(case when workclassid = 'so' then workclosedutcdatetime else null end)) / (60 * 60 * 24)) + ':'
+ convert(varchar, dateadd(s, datediff(s, min(case when workclassid = 'so' then workclosedutcdatetime else null end), 
max(case when workclassid = 'so' then workclosedutcdatetime else null end)), convert(datetime2, '0001-01-01')), 108)  [SO Pick Time] ,

count(distinct case when workstatus like '%stage%' then itemid    else null end) [# of Stage Lines],

convert(varchar, datediff(s, min(case when workstatus like '%stage%' then workclosedutcdatetime else null end), 
max(case when workstatus like '%stage%' then workclosedutcdatetime else null end)) / (60 * 60 * 24)) + ':'
+ convert(varchar, dateadd(s, datediff(s, min(case when workstatus like '%stage%' then workclosedutcdatetime else null end), 
max(case when workstatus like '%stage%' then workclosedutcdatetime else null end)), convert(datetime2, '0001-01-01')), 108) [Stage Time] ,

count(distinct case when workstatus like '%packing%' then itemid else null end) [# of Packing lines],

convert(varchar, datediff(s, min(case when workstatus like '%packing%' then workclosedutcdatetime else null end), 
max(case when  workstatus like '%packing%' then workclosedutcdatetime else null end)) / (60 * 60 * 24)) + ':'
+ convert(varchar, dateadd(s, datediff(s, min(case when workstatus like '%packing%' then workclosedutcdatetime else null end), 
max(case when workstatus like '%packing%' then workclosedutcdatetime else null end)), convert(datetime2, '0001-01-01')), 108) [Packing Time],

convert(varchar, datediff(s, min(workclosedutcdatetime), 
max(workclosedutcdatetime)) / (60 * 60 * 24)) + ':'
+ convert(varchar, dateadd(s, datediff(s, min(workclosedutcdatetime), 
max(workclosedutcdatetime)), convert(datetime2, '0001-01-01')), 108) [Total time of shipment]

from #temp 
group by shipmentid