仅在MySQL中返回最近3个月的记录 [英] Returning records from the last 3 months only in MySQL

查看:119
本文介绍了仅在MySQL中返回最近3个月的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有时间戳字段的表.如何获取最近3个月的数据?

I have a table with a timestamp field. How do I get data from the last 3 months?

特别是,3月是我当月的月份,例如 03/2012 .我只需要返回3月,2月和1月的记录.

In particular, March is my current month let say, 03/2012. I need to return records from the months March, February, and January only.

推荐答案

今天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中返回最近3个月的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆