每天插入文档的SQL平均时间(ReportBuilder)

时间:2017-04-04 10:07:58

标签: sql datetime average reportbuilder

我被困在如何在同一天插入文件的平均时间。

到目前为止我的代码:

SELECT DISTINCT  
      ,b.FileID
      ,b.Userr
      ,b.docInsert
      ,CONVERT(varchar,(docInsert), 111) as daz
      ,CONVERT(varchar,(docInsert), 108) as C1
      ,(SELECT CONVERT(varchar,(MAX(docInsert)), 108) FROM DOCC AS C WHERE C.docInsert < b.docInsert and b.userr like '1') AS prev
      ,CONVERT(varchar,(b.docInsert - (SELECT CONVERT(varchar,(MAX(docInsert)), 108) FROM DOCC AS C WHERE C.docInsert < b.docInsert and b.userr like '1')), 108) as worked
      ,DATEPART(HOUR,CONVERT(varchar,(b.docInsert - (SELECT CONVERT(varchar,(MAX(docInsert)), 108) FROM DOCC AS C WHERE C.docInsert < b.docInsert and b.userr like '1')), 108)) as h
      ,DATEPART(MINUTE,CONVERT(varchar,(b.docInsert - (SELECT CONVERT(varchar,(MAX(docInsert)), 108) FROM DOCC AS C WHERE C.docInsert < b.docInsert and b.userr like '1')), 108)) as m
      ,DATEPART(SECOND,CONVERT(varchar,(b.docInsert - (SELECT CONVERT(varchar,(MAX(docInsert)), 108) FROM DOCC AS C WHERE C.docInsert < b.docInsert and b.userr like '1')), 108)) as s

   FROM DOCC b
   WHERE
   b.userr like '1'
   and DATEPART(HOUR, (CONVERT(varchar,(b.docInsert - (SELECT CONVERT(varchar,(MAX(docInsert)), 108) FROM DOCC AS C WHERE C.docInsert < b.docInsert)), 108))) < '15'


 ORDER BY userr, docInsert

我的输出:

FileID                           userr      docInsert           daz         C1          prev        worked      h   m   s
5e1933733ddb3c7f0128bb38f1a0f62     1   2017-04-03 08:31:03.537 2017/04/03  08:31:03    08:01:39    00:29:24    0   29  24
c9384192001d75432b9bdb2e47f8ed6     1   2017-04-03 08:42:21.337 2017/04/03  08:42:21    08:31:03    00:11:18    0   11  18
fe9794a4ea0e97f53d8987e9876a14e     1   2017-04-03 08:46:34.213 2017/04/03  08:46:34    08:42:21    00:04:13    0   4   13
b1ba6aaeb924cf6d4dd5f14669c09f5     1   2017-04-03 09:09:38.630 2017/04/03  09:09:38    08:46:34    00:23:04    0   23  4
a35a05864767a3eb0fa328365a6341c     1   2017-04-03 09:51:09.003 2017/04/03  09:51:09    09:09:38    00:41:31    0   41  31
5a19275a0daf363dfab44617779ac52     1   2017-04-03 10:02:31.353 2017/04/03  10:02:31    09:51:09    00:11:22    0   11  22
3a63961e0739dfdbee7cafff7705f7a     1   2017-04-03 10:27:51.940 2017/04/03  10:27:51    10:02:31    00:25:20    0   25  20
e85c478ac460fe4db7fd293998f2c9b     1   2017-04-03 11:09:39.333 2017/04/03  11:09:39    10:27:51    00:41:48    0   41  48
f8a377d871127ac463e642439bb2830     1   2017-04-03 11:10:57.427 2017/04/03  11:10:57    11:09:39    00:01:18    0   1   18
ef58294b5cf8c3bbdf32dfee8492c1e     1   2017-04-03 11:24:46.930 2017/04/03  11:24:46    11:10:57    00:13:49    0   13  49
aa176b6d39356c9abb08ad1855aa584     1   2017-04-03 11:26:13.777 2017/04/03  11:26:13    11:24:46    00:01:27    0   1   27
6497a0547e5cf448442667c740b0d4f     1   2017-04-03 11:27:41.323 2017/04/03  11:27:41    11:26:13    00:01:28    0   1   28
fd1b0f53c78bf0735f3c73ff7fee685     1   2017-04-03 11:58:49.787 2017/04/03  11:58:49    11:27:41    00:31:08    0   31  8
6b42455825c84cb4002aa475b713643     1   2017-04-03 12:00:44.587 2017/04/03  12:00:44    11:58:49    00:01:55    0   1   55

053cbac93fa652f4b68a1fd17efbdee     1   2017-04-04 08:15:58.827 2017/04/04  08:15:58    08:13:40    00:02:18    0   2   18
4180044a3b96ff445b1e84c6eca707a     1   2017-04-04 08:17:04.780 2017/04/04  08:17:04    08:15:58    00:01:06    0   1   6
1a0741b87075177c4df4e196e8267a3     1   2017-04-04 08:30:38.690 2017/04/04  08:30:38    08:17:04    00:13:34    0   13  34
45ac472092767a33a808ab2b7bb363b     1   2017-04-04 08:31:28.300 2017/04/04  08:31:28    08:30:38    00:00:50    0   0   50
18425098ecbeaf357445c9a53ecc485     1   2017-04-04 08:33:01.927 2017/04/04  08:33:01    08:31:28    00:01:33    0   1   33
e942097f1247417f0a13c3f51197ae9     1   2017-04-04 08:34:49.663 2017/04/04  08:34:49    08:33:01    00:01:48    0   1   48
3f840554fae442b90ba47b956267c1f     1   2017-04-04 08:36:45.163 2017/04/04  08:36:45    08:34:49    00:01:56    0   1   56
17113c49ded52ce5d20ec10d6410865     1   2017-04-04 08:42:18.103 2017/04/04  08:42:18    08:36:45    00:05:33    0   5   33
d1b567fc7a531f6869f04abfcf7c86e     1   2017-04-04 09:56:03.333 2017/04/04  09:56:03    08:42:18    01:13:45    1   13  45
5726268584374b385afff14b666d44e     1   2017-04-04 10:47:00.650 2017/04/04  10:47:00    09:56:03    00:50:57    0   50  57
2cc89f4e6b19b7a390eb8b98cfd0f99     1   2017-04-04 10:49:17.200 2017/04/04  10:49:17    10:47:00    00:02:17    0   2   17
686fd199b6e4357a4d4983b1bc7c567     1   2017-04-04 10:57:29.670 2017/04/04  10:57:29    10:49:17    00:08:12    0   8   12

你可以看到我的代码很糟糕,我仍然在日复一日地学习。 在我把“工作&lt; 15h”放在哪里因为,我不想在输出中输出前一天/下一天的文件。 我试图在几秒钟内更改“工作”列,以便我可以在ReportBuilder(count(fileID))和(sum(avg(working)))中进行计算但是出错了。

或者任何其他选项/建议如何以适当的方式做到这一点也会很棒。

谢谢

0 个答案:

没有答案