-1

我有这样一个表,其中包含如下数据

ReferenceNo                 CommentDate             StepName            Originator  StartTime
1   CHQRCL/0083/2013/FEB    2013-02-25 15:20:07.000 Initiate Process    P8Admin 2013-02-25 15:20:07.000
1   CHQRCL/0083/2013/FEB    2013-02-25 15:20:44.000 Finance Controller  P8Admin 2013-02-25 15:20:07.000
1   CHQRCL/0083/2013/FEB    2013-02-25 15:21:52.000 Originator  P8Admin 2013-02-25 15:20:07.000
1   CHQRCL/0083/2013/FEB    2013-02-25 15:23:26.000 Finance Controller  P8Admin 2013-02-25 15:20:07.000
1   CHQRCL/0083/2013/FEB    2013-02-25 15:23:55.000 Finance Officer P8Admin 2013-02-25 15:20:07.000
2   CHQRCL/0089/2013/FEB    2013-02-25 15:43:48.000 Initiate Process    P8Admin 2013-02-25 15:43:48.000
2   CHQRCL/0089/2013/FEB    2013-02-25 15:43:59.000 Finance Controller  P8Admin 2013-02-25 15:43:48.000
2   CHQRCL/0089/2013/FEB    2013-02-25 15:44:11.000 Asset GM    P8Admin 2013-02-25 15:43:48.000
3   CHQRCL/0093/2013/MAR    2013-03-06 16:19:05.000 Initiate Process    P8Admin 2013-03-06 16:19:05.000
3   CHQRCL/0093/2013/MAR    2013-03-06 16:21:57.000 Finance Controller  P8Admin 2013-03-06 16:19:05.000
3   CHQRCL/0093/2013/MAR    2013-03-06 16:23:55.000 Asset GM    P8Admin 2013-03-06 16:19:05.000
3   CHQRCL/0093/2013/MAR    2013-03-06 16:24:09.000 CFO P8Admin 2013-03-06 16:19:05.000
3   CHQRCL/0093/2013/MAR    2013-03-06 16:24:19.000 CEO P8Admin 2013-03-06 16:19:05.000
3   CHQRCL/0093/2013/MAR    2013-03-06 16:24:40.000 Finance Officer P8Admin 2013-03-06 16:19:05.000
4   CHQRCL/0094/2013/MAR    2013-03-06 16:58:47.000 Initiate Process    P8Admin 2013-03-06 16:58:47.000
4   CHQRCL/0094/2013/MAR    2013-03-06 17:00:45.000 Finance Controller  P8Admin 2013-03-06 16:58:47.000
4   CHQRCL/0094/2013/MAR    2013-03-06 17:00:54.000 Asset GM    P8Admin 2013-03-06 16:58:47.000
4   CHQRCL/0094/2013/MAR    2013-03-06 17:04:48.000 CFO P8Admin 2013-03-06 16:58:47.000
4   CHQRCL/0094/2013/MAR    2013-03-06 17:05:06.000 CEO P8Admin 2013-03-06 16:58:47.000
4   CHQRCL/0094/2013/MAR    2013-03-06 17:05:35.000 Finance Officer P8Admin 2013-03-06 16:58:47.000
5   CHQRCL/0108/MAR/2013    2013-03-10 08:58:22.000 Initiate Process    Mohamed Ubaid   2013-03-10 08:58:22.000
5   CHQRCL/0108/MAR/2013    2013-03-10 09:06:23.000 Finance Controller  Mohamed Ubaid   2013-03-10 08:58:22.000
5   CHQRCL/0108/MAR/2013    2013-03-10 09:07:06.000 Finance Officer Mohamed Ubaid   2013-03-10 08:58:22.000
6   CHQRCL/0110/MAR/2013    2013-03-10 09:26:10.000 Initiate Process    Allan C Fampulme    2013-03-10 09:26:10.000
6   CHQRCL/0110/MAR/2013    2013-03-10 09:32:34.000 Finance Controller  Allan C Fampulme    2013-03-10 09:26:10.000
6   CHQRCL/0110/MAR/2013    2013-03-10 09:33:22.000 Asset GM    Allan C Fampulme    2013-03-10 09:26:10.000
6   CHQRCL/0110/MAR/2013    2013-03-10 09:35:39.000 Originator  Allan C Fampulme    2013-03-10 09:26:10.000
6   CHQRCL/0110/MAR/2013    2013-03-10 09:36:06.000 Asset GM    Allan C Fampulme    2013-03-10 09:26:10.000
6   CHQRCL/0110/MAR/2013    2013-03-10 09:36:20.000 CFO Allan C Fampulme    2013-03-10 09:26:10.000
6   CHQRCL/0110/MAR/2013    2013-03-10 09:36:41.000 CEO Allan C Fampulme    2013-03-10 09:26:10.000
6   CHQRCL/0110/MAR/2013    2013-03-10 09:37:34.000 Finance Officer Allan C Fampulme    2013-03-10 09:26:10.000

首先,我想要每个参考号的每个步骤所花费的时间(例如,对于参考号 1 的财务控制器,它需要 37 秒)。我想计算平均值(以相同的财务控制器步骤为例;1 refNo + 94 秒再次在 1refNo + 11 秒在 2refNo + 中花费 7 秒,依此类推除以 6)

4

1 回答 1

0

我使用以下查询解决了我的问题,

WITH CTE AS(
SELECT ROW_NUMBER()OVER(PARTITION BY ReferenceNo ORDER BY CommentDate)As RowNum, *
FROM FNCUSTOM.dbo.WorkflowHistory T
)

SELECT ReferenceNo, StepName, CommentDate, DiffDays = DATEDIFF( s,(从 CTE c2 中选择 CommentDate,其中 c2.ReferenceNo = CTE.ReferenceNo AND c2.RowNum=CTE.RowNum-1),CommentDate)/60.0 / 60.0 / 24.0
从 CTE

于 2013-03-18T10:26:46.053 回答