0
我有以下表行和基於列DATEDIFF
ROW StartDT EndDT USERID LOCATION
----------------------------------------------------------------------------------
R1 2017-05-24 15:39:36.000 NULL 1 Loc1
R2 2017-05-24 11:10:26.000 2017-05-24 11:13:43.000 2 Loc1
R3 2017-05-24 11:57:50.000 2017-05-24 12:00:04.000 3 Loc1
輸出邏輯應該
For location = Loc1, datediff(minutes, (R2.EndDT - R3.StartDT))
如果EndDT
具有null
值那麼結果應顯示NULL
如何爲此編寫SQL查詢?
最新的SQL服務器版本有LEAD,LAG – Serg
選擇R2行和R3行,但不是R1的邏輯是什麼? –