Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个具有以下结构的连接表:
->ip ->first (datetime of the entry creation) ->last (datetime of last update to the entry)
日期时间的格式为Y-m-d H:i:s.
Y-m-d H:i:s
现在我想删除每个具有last - first > 5 minutesas 的条目true。如何在 SQL 查询中做到这一点?
last - first > 5 minutes
true
只需将其添加为 where 条件
DELETE FROM `table` WHERE `last` - `first` > 5;
使用TIMESTAMPDIFF
DELETE FROM `tableName` WHERE TIMESTAMPDIFF(MINUTE,`first`,`last`) > 5