简体   繁体   English

根据时间戳分钟删除行

[英]Delete rows based on timestamp minute

How to delete rows based on timestamp in same minute. 如何在同一分钟内根据时间戳删除行。 ex: 例如:

id|temp| dt
1 | 20 | 2015-10-08 06:45:04
2 | 20 | 2015-10-08 06:40:03
3 | 21 | 2015-10-08 06:35:03
4 | 20 | 2015-10-08 06:20:04

I want to delete only records in the minute 5 (ids 1 and 3) I tried delete from table where minute(dt)=5 and works partially (?) 我想删除分钟5中的记录(ids 1和3)我尝试delete from table where minute(dt)=5并且部分工作(?)

Try this: 尝试这个:

DELETE FROM mytable 
WHERE (minute(dt) - 5) % 10 = 0

This deletes all rows whose minute value ends at 5 (if this is what you really want). 这将删除分钟值结束为5所有行(如果这是您真正想要的)。

Simpler version of the above query (thanks to @Gordon): 上述查询的更简单版本(感谢@Gordon):

DELETE FROM mytable 
WHERE minute(dt) % 10 = 5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM