删除所有时间戳记早于x天的行 [英] Delete all rows with timestamp older than x days
本文介绍了删除所有时间戳记早于x天的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从数据库中的特定表中删除所有时间戳超过180天的行.
I want to delete all the rows with timestamp older than 180 days from a specific table in my database.
我已经尝试过了:
DELETE FROM on_search WHERE search_date < DATE_SUB(NOW(), INTERVAL 180 DAY);
但是,这删除了所有行,而不仅删除了6个月以上的行.
But that deleted all the rows and not only the rows older than 6 months.
我在on_search表中有一列称为search_date,其中包含创建该行的时间.
I have a column in on_search table called search_date and contains the time when that row was created.
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))
这篇关于删除所有时间戳记早于x天的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文