[英]check if a period is included between two dates
i've a mysql table like this: 我有一个像这样的mysql表:
| ID | ID_period | date_start | date_end |
| 1 | 1 | 0000-07-01 | 0000-08-31 |
| 2 | 2 | 0000-09-01 | 0000-10-30 |
| 3 | 3 | 0000-11-01 | 0000-12-28 |
| 4 | 4 | 0000-11-01 | 0000-03-31 |
how can i select IDs that are included between this period 0000/07/14 - 0000/08/25 ? 如何选择此时间段0000/07/14-0000/08/25之间包含的ID?
date_start and date_end columns are DATE format. date_start和date_end列均为DATE格式。
THE PROBLEM is that if i search for a period (included and intersect) that is ie: from 0000-12-12 to 0000-01-25 i get 0 records from the select, i guess for the year that is '0000'.. how can i fix it ? 问题是,如果我搜索一个时期(包括和相交),即:从0000-12-12到0000-01-25,我从选择中得到0条记录,我猜年份是'0000'。我该如何解决?
another problem is that if i search a period like 11-01 to 12-31 i got 0 results.. because last day od december in date_end is 28.. but if i search for a period 11-01 to 12-31 is because i want all the records included.. so i'd like to get the record having id=3 and id=4 另一个问题是,如果我搜索11-11至12-31之类的期间,我会得到0个结果..因为date_end中12月的最后一天是28 ..但是如果我搜索11-01至12-31的时期是因为我想要包括所有记录..所以我想获得具有id = 3和id = 4的记录
at the moment im using the following query: 目前,即时通讯使用以下查询:
SELECT ... WHERE '12' BETWEEN MONTH(date_start) and MONTH(date_end)
AND '15' BETWEEN DAY(date_start) and DAY(date_end)
AND '03' BETWEEN MONTH(date_start) and MONTH(date_end)
AND '28' BETWEEN DAY(date_start) and DAY(date_end)
SELECT *
FROM mytable
WHERE date_start BETWEEN '0000-07-14' AND '0000-08-25'
OR date_end BETWEEN '0000-07-14' AND '0000-08-25'
OR (date_start<'0000-07-14' AND date_end>'0000-08-25')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.