2014-11-25 136 views
-1
THENUMBER  NUMBER  SYSMODTIME    TYPE 
ACTIM2816332 IM0540202 2014-11-18 09:17:53.000 Closed 
ACTIM2806050 IM0540202 2014-11-13 15:11:29.000 Update 
ACTIM2806051 IM0540202 2014-11-13 15:11:29.000 External Vendor Assignment 
ACTIM2806049 IM0540202 2014-11-13 15:11:29.000 Status Change 
ACTIM2806046 IM0540202 2014-11-13 15:10:34.000 Assignment 
ACTIM2804167 IM0540202 2014-11-13 09:31:12.000 Status Change 
ACTIM2804166 IM0540202 2014-11-13 09:31:12.000 Assignment 
ACTIM2802130 IM0540202 2014-11-12 17:09:57.000 Open 

請幫我創建一個選擇來計算從打開到關閉的類型更改之間的時間差?sql服務器狀態更改時間

我需要成爲一個通用的不同的NUMBER。

+0

你想要什麼的區別?幾分鐘,幾小時,幾天等? – Matt 2014-11-25 10:56:53

+0

在幾分鐘或幾小時內 – user1246645 2014-11-25 11:01:37

+0

都做了回答 – Matt 2014-11-25 11:02:20

回答

1

分鐘

SELECT NUMBER, MAX([SYSMODTIME]) AS Closed, MIN([SYSMODTIME]) AS Open, 
(DATEDIFF (mi, MAX([LoginDateTime]), MIN([SYSMODTIME]))) AS [datediff] 
FROM table 
GROUP BY NUMBER 

小時

SELECT NUMBER, MAX([SYSMODTIME]) AS Closed, MIN([SYSMODTIME]) AS Open, 
(DATEDIFF (hh, MAX([LoginDateTime]), MIN([SYSMODTIME]))) AS [datediff] 
FROM table 
GROUP BY NUMBER