mysql - How to get data by date range given only month and year

前端 未结 5 669
轮回少年
轮回少年 2021-01-15 16:18

Below is my mysql table:

--------------------------
ID  Date_From   Date_To
--------------------------
1   2011-02-01  2011-02-28
2   2012-09-01  2012-09-30
         


        
5条回答
  •  不知归路
    2021-01-15 16:58

    You can create a separate column as year_month like YYYYMM and create two triggers to automatically update the column ON INSERT and ON UPDATE if required.

    Then the query would be as simple as

    WHERE year_month >= 201210 and year_month <= 201312

提交回复
热议问题