How to select last 6 months from news table using MySQL

前端 未结 6 1899
生来不讨喜
生来不讨喜 2020-12-07 16:22

I am trying to select the last 6 months of entries in a table, I have a column called datetime and this is in a datetime mysql format.

I have seen many ways using in

6条回答
  •  甜味超标
    2020-12-07 17:19

    I tried @user319198 answer to display last 6 months (sum of) sales, it worked but I faced one issue in the oldest month, i do not get the sales amount of the whole month. The result starts from the equivalent current day of that month.

    Just I want to share my solution if any one interested:-

    yourdate_column > DATE_SUB(now(), INTERVAL 7 MONTH)
    limit 6
    

    Also it will be great if anyone has better solution for my case J.

提交回复
热议问题