包含4个字段,如:
id Start_date End_date Package
-- --------- ---------- --------
1 2013-10-25 2014-04-30 pack 1
2 2014-01-02 2014-04-30 Pack 2
3 2014-05-01 2015-06-30 pack 3
4 2015-07-01 pack 4
我想使用date(start = 2014-01-01和end = 2014-08-13)来检查日期是否在表格中的任何日期(Start_date,End_date)之间。对于这种情况,我想获得第1包,第2包和第3包。我该怎么做?
答案 0 :(得分:0)
使用mysql的BETWEEN关键字
SELECT * FROM table WHERE ( start_date BETWEEN date_from and date_to ) OR ( end_date BETWEEN date_from and date_to)
答案 1 :(得分:-1)
SELECT * FROM table WHERE '2014-01-01' <= Start_date AND '2014-08-13' >= End_date