MySQL select all rows from last month until (now() - 1 month), for comparative purposes

后端 未结 10 494
北海茫月
北海茫月 2020-12-07 18:12

I need some help writing a MySQL query to show me rows from last month, but not the whole month, only up and until the same day, hour and minute as it is now(), but 1 month

10条回答
  •  隐瞒了意图╮
    2020-12-07 18:47

    You could use a WHERE clause like:

    WHERE DateColumn BETWEEN
        CAST(date_format(date_sub(NOW(), INTERVAL 1 MONTH),'%Y-%m-01') AS date)
        AND
        date_sub(now(), INTERVAL 1 MONTH)
    

提交回复
热议问题