我有像这样的表结构
id from to
1 2014-02-01 00:00:00 2014-02-28 00:00:00
2 2014-01-01 00:00:00 2014-01-30 00:00:00
3 2014-03-01 00:00:00 2014-03-30 00:00:00
并且此
中没有重叠的日期范围我试图通过传递范围
的日期来选择记录例如。传递日期'2014-01-16'
应该返回id=2
的记录,因为它在此行的日期范围内,请引导我解决此问题。
提前致谢
答案 0 :(得分:1)
SELECT * FROM mytable
WHERE '2014-01-16' BETWEEN `from` AND `to`
<强> SQLFiddle 强>
答案 1 :(得分:0)
SELECT id FROM table WHERE from <= '2014-01-16' AND to >= '2014-01-16'