insert into mytable values
('100', '2015-07-14', '2015-07-25'),
('200', '2015-07-28', '2015-07-30')
当我在上表中搜索时,我需要如下结果
示例:
我尝试下面的查询
select * from mytable where
valid_from <= '2015-07-29' and valid_to >= '2015-07-13'
但它显示结果可用。 这里的日期是13,26和&amp; 27不在表中。
答案 0 :(得分:0)
只需在查询中添加一些约束:
select * from mytable where
valid_to >= '2015-07-29' and valid_to <= '2015-07-13' and valid_from >= '2015-07-29' and valid_from <= '2015-07-13';
答案 1 :(得分:0)
试试此代码
select * from mytable where
(valid_to between '2015-07-29' and '2015-07-13')
and
(valid_from between '2015-07-29' and '2015-07-13');
我建议您在UNIX时间戳(Epoch格式)中使用日期。