问题
I have a date range like
date from=2011-10-14 & date to=2011-10-20
if I have another date ranges
like
- 2011-10-11 - 2011-10-15
- 2011-10-11 - 2011-10-21
- 2011-10-15 - 2011-10-21
- 2011-10-15 - 2011-10-19
- 2011-10-21 - 2011-10-26
I want sql query which shows only the date range whose dates lies in between above (2011-10-14 & date to=2011-10-20)
date range.
Here only 2011-10-21 - 2011-10-26
does not lies in date from=2011-10-14 & date to=2011-10-20
Result must show
- 2011-10-11 - 2011-10-15
- 2011-10-11 - 2011-10-21
- 2011-10-15 - 2011-10-21
- 2011-10-15 - 2011-10-19
these dates
Hope you understand what I am asking.
回答1:
date_from < '2011-10-20' AND date_to > '2011-10-14'
回答2:
SELECT * FROM datetable where mydate BETWEEN '2011-10-14' AND '2011-10 20';
回答3:
WHERE date_from >= '2011-10-14' AND date_to <= '2011-10-20'
?
But this will only work if you have your column's data type set to DATE
or DATETIME
回答4:
You can go and search on the Internet :-)
The first links you will come across is this: http://www.c-sharpcorner.com/Blogs/692/
Hope the above link helps in resolving your query.
Or, you could give something like this:
SELECT * FROM myTBL
WHERE myReqDate NOT BETWEEN '2011-10-14' AND '2011-10-20'
来源:https://stackoverflow.com/questions/7304504/how-to-check-a-dates-of-a-date-range-lies-in-between-two-dates-in-mysql-query