我有一个带有时间戳字段的表。如何获取最近 3 个月的数据?
特别是,三月是我当前的月份,比方说,03/2012。我只需要返回三月、二月和一月的记录。
最佳答案
今天前 3 个月:
select * from table where timestamp >= now()-interval 3 month;
从月初开始:
select * from table where timestamp >= last_day(now()) + interval 1 day - interval 3 month;
关于mysql - 仅在 MySQL 中返回最近 3 个月的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15397015/