Get the values for last 6 months in mysql

前端 未结 4 1175
梦谈多话
梦谈多话 2021-01-14 10:33

I need to get last six month values from the database. Here is my Fiddle. I need to get the values dynamically. Now February. So I need August to Januar

4条回答
  •  一个人的身影
    2021-01-14 11:06

    SQLFiddle

    If you want full months only

    SELECT *
    FROM ratepersqft
    WHERE date between date_format(DATE_SUB(CURDATE(), INTERVAL 6 MONTH), '%Y-%m-01')
               and  date_sub(date_format(CURDATE(), '%Y-%m-01'), interval 1 day);
    

提交回复
热议问题