MySQL Query to calculate the Previous Month

后端 未结 6 817
野的像风
野的像风 2020-12-02 20:53

I would like to calculate total order amount in the previous month.

I got the query for getting the data for the present month from the current date.



        
6条回答
  •  鱼传尺愫
    2020-12-02 21:34

    I found that Artem's query wasn't returning anything from the last day of the previous month(presumably as BETWEEN would calculate from time 00:00:00 of the last day).

    This seems to work for me for the previous month.

    order_placed_date BETWEEN DATE_FORMAT(NOW() - INTERVAL 1 MONTH, '%Y-%m-01')
    AND DATE_FORMAT(NOW() ,'%Y-%m-01')
    

提交回复
热议问题