Working with INTERVAL and CURDATE in MySQL

后端 未结 3 1897
忘了有多久
忘了有多久 2020-12-01 05:13

I\'m building a chart and I want to receive data for each month.

Here\'s my first request which is working:

SELECT s.GSP_nom AS nom, timestamp, AVG         


        
3条回答
  •  遥遥无期
    2020-12-01 05:52

    As suggested by A Star, I always use something along the lines of:

    DATE(NOW()) - INTERVAL 1 MONTH
    

    Similarly you can do:

    NOW() + INTERVAL 5 MINUTE
    "2013-01-01 00:00:00" + INTERVAL 10 DAY
    

    and so on. Much easier than typing DATE_ADD or DATE_SUB all the time :)!

提交回复
热议问题