我有下表叫做季节
+----+--------+------------+------------+
| id | cost | start | end |
+----+--------+------------+------------+
| 33 | 255 | 2014-01-05 | 2014-04-16 |
| 17 | 357 | 2014-04-17 | 2014-04-19 |
| 65 | 191.25 | 2014-04-20 | 2014-07-10 |
| 49 | 255 | 2014-07-11 | 2014-08-23 |
| 81 | 191.25 | 2014-08-24 | 2014-12-18 |
+----+--------+------------+------------+
我试图使用以下查询获得开始和结束之间的日期范围.
SELECT
*
FROM
seasons
WHERE
(start BETWEEN '2014-01-05' AND '2014-01-05' OR end BETWEEN '2014-01-05' AND '2014-01-05');
如果开始日期恰好在字段上的值上开始,我就能得到结果集.
+----+------+------------+------------+
| id | cost | start | end |
+----+------+------------+------------+
| 33 | 255 | 2014-01-05 | 2014-04-16 |
+----+------+------------+------------+
现在的问题是我将日期提前到
2014-01-06
SELECT
*
FROM
seasons
WHERE
(start BETWEEN '2014-01-06' AND '2014-01-06' OR end BETWEEN '2014-01-06' AND '2014-01-06');
Empty set (0.00 sec)
没有结果.如何获取SQL之间不同字段的日期范围?
任何帮助表示赞赏.
解决方法:
你的逻辑落后了.如果您想要在该季节中给定日期的季节,那么您的where子句应如下所示:
WHERE '2014-01-06' BETWEEN start AND end;