MySQL Query to calculate the Previous Month

后端 未结 6 809
野的像风
野的像风 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条回答
  •  -上瘾入骨i
    2020-12-02 21:29

    Simplest solution:

    SELECT SUM(goods_total) AS Total_Amount FROM orders
    WHERE YEAR(order_placed_date) = YEAR(CURDATE() - INTERVAL 1 MONTH)
    AND MONTH(order_placed_date) = MONTH(CURDATE() - INTERVAL 1 MONTH)
    

提交回复
热议问题