Returning records from the last 3 months only in MySQL

后端 未结 4 1352
野性不改
野性不改 2020-12-01 07:35

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

In particular, March is my current month let say, 03/2012. I need to retur

4条回答
  •  被撕碎了的回忆
    2020-12-01 08:14

    3 months before today:

    select * from table where timestamp >= now()-interval 3 month;
    

    Start with first of month:

    select * from table where timestamp >= last_day(now()) + interval 1 day - interval 3 month;
    

提交回复
热议问题