2014-10-08 123 views
0

我試圖計算用戶登錄/註銷之間的時間差,爲此,我需要執行以下操作:第二次登錄 - 第一次登出,我不知道甚至如何解釋正確,所以我會在這裏發佈表的結果來說明:
計算不同列和行之間的時間差異[MYSQL]

enter image description here

+0

後,下次登錄這是你需要什麼? http://stackoverflow.com/questions/10907750/calculate-difference-between-two-datetimes-in-mysql或 http://stackoverflow.com/questions/4759248/difference-between-two-dates-in-mysql – trainoasis 2014-10-08 12:53:34

+0

嘗試將示例數據和期望的結果放入您的問題中。 – 2014-10-08 12:53:45

+1

你可以分享你的餐桌結構嗎? – Mureinik 2014-10-08 12:54:42

回答

0

您可以通過自身左側的接合部表acomplish這一點。此查詢使您發佈的表:

SELECT t.Login, t.Logout, TIMEDIFF(MIN(t2.Login), t.Logout) AS Difference 
FROM my_table t 
LEFT JOIN my_table t2 
ON t.Logout < t2.Login 
GROUP BY t.Logout 

MIN(t2.Login)是t.Logout

相關問題