I have a holiday record that has a start_date and an end_date
I want to do a query where I have to dates '2015-05-05' and '2015-06-05' I want to see which holiday records fall in between these dates and could overlay so for example one holiday record may have a start_date of '2015-06-01' and end_date of '2015-07-10'. I would want that to be picked up in the query
How would you write a query to do so?
Try something like this:
select * from tablename
where (start_date, end_date) OVERLAPS ('2015-05-05', '2015-06-05')
You can find details about OVERLAPS
on this page: http://www.postgresql.org/docs/current/static/functions-datetime.html
Try this
select * from tablename
where
'2015-05-05' between start_date and end_date or
'2015-06-05' between start_date and end_date or
(start_date<='2015-05-05' and end_date>='2015-06-05')
Try this query
select * from tablename
where start_date between '2015-05-05' and '2015-06-05' and end_date between '2015-05-05' and '2015-06-05'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.