检查这个
create table mytable(inputDate text, start_date DATE,end_date DATE);
insert into mytable values('2013-01-01',to_date('2013-01-01', 'YYYY-MM-DD'),to_date('2013-12-23', 'YYYY-MM-DD'));
insert into mytable values('2014-01-01',to_date('2013-01-01', 'YYYY-MM-DD'),to_date('2013-12-23', 'YYYY-MM-DD'));
insert into mytable values('2013-12-24',to_date('2013-01-01', 'YYYY-MM-DD'),to_date('2013-12-23', 'YYYY-MM-DD'));
insert into mytable values('2014-12-24',to_date('2013-01-01', 'YYYY-MM-DD'),to_date('2013-12-23', 'YYYY-MM-DD'));
查询以检查忽略年份的范围
select * from mytable
where
(
date_part('month',to_date(inputDate,'YYYY-MM-DD')) >=date_part('month',start_date)
AND
date_part('day',to_date(inputDate,'YYYY-MM-DD')) >=date_part('day',start_date)
)
AND
(
date_part('month',to_date(inputDate,'YYYY-MM-DD')) <=date_part('month',end_date)
AND
date_part('day',to_date(inputDate,'YYYY-MM-DD')) <=date_part('day',end_date)
)
SQL 小提琴演示