简体   繁体   English

删除所有时间戳早于 x 天的行

[英]Delete all rows with timestamp older than x days

I want to delete all the rows with timestamp older than 180 days from a specific table in my database.我想从数据库中的特定表中删除时间戳早于 180 天的所有行。

I've tried the this:我试过这个:

DELETE FROM on_search WHERE search_date < DATE_SUB(NOW(), INTERVAL 180 DAY);

But that deleted all the rows and not only the rows older than 6 months.但这删除了所有行,而不仅仅是超过 6 个月的行。

I have a column in on_search table called search_date and contains the time when that row was created.我在 on_search 表中有一个名为 search_date 的列,其中包含创建该行的时间。

search_id   search_term    search_date 
660779      car games      1390052553 
DELETE FROM on_search 
WHERE search_date < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 180 DAY))
DELETE FROM on_search WHERE search_date < NOW() - INTERVAL N DAY

用您的天数替换 N

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

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