我有一個表爲具有以下結構的連接:如何刪除MySQL中不在時間範圍內的所有條目?
->ip
->first (datetime of the entry creation)
->last (datetime of last update to the entry)
日期時間是在格式Y-m-d H:i:s
。
現在我想刪除每個條目last - first > 5 minutes
作爲true
。我怎麼能在SQL查詢中做到這一點?
我有一個表爲具有以下結構的連接:如何刪除MySQL中不在時間範圍內的所有條目?
->ip
->first (datetime of the entry creation)
->last (datetime of last update to the entry)
日期時間是在格式Y-m-d H:i:s
。
現在我想刪除每個條目last - first > 5 minutes
作爲true
。我怎麼能在SQL查詢中做到這一點?
DELETE FROM `tableName` WHERE TIMESTAMPDIFF(MINUTE,`first`,`last`) > 5
簡單地將其添加爲where條件
DELETE FROM `table` WHERE `last` - `first` > 5;
請看看我編輯的問題,我錯了,說時間戳,現在我糾正了我的問題。 –
肯定是時間戳,而不是日期時間?我沒有看到問題,否則:) –
我忘了提及,5是在幾分鐘內。 –
last-first> 5 * 60? –