两个日期之间的日期查询

时间:2011-06-09 18:07:17

标签: php mysql cakephp-1.3

在我的表中我有这个架构

record      startDate    endDate
abs         2005-11-29   2005-11-21
absasd          2005-11-23   2005-01-22
absty           2005-10-26   2005-02-23
absfx           2005-09-27   2005-09-24
absft           2005-10-28   2005-07-25
absyh           2005-01-28   2005-08-01
absdx           2005-12-29   2005-01-02
abs345          2005-06-24   2005-02-03
abser           2005-07-14   2005-04-06
absbv       2005-08-01   2005-05-08
abse        2005-07-12   2005-06-09
abserr          2005-12-30   2005-07-14
absf        2005-01-12   2005-12-16
abscv           2005-04-11   2005-12-26
abscv           2005-06-01   2005-11-27
absc        2005-07-03   2005-10-28
absv        2005-07-06   2005-09-25
.....
.....
......

我想选择介于2005-01-01和2005-10-01之间的所有记录。和某些其他日期。什么是sql。

2 个答案:

答案 0 :(得分:4)

SELECT *
    FROM YourTable
    WHERE startDate >= '2005-01-01'
        AND endDate <= '2005-10-01'

答案 1 :(得分:1)

声誉为1K +这个问题?你还好吗? : - )

SELECT * FROM TableName
WHERE startDate > '2005-01-01' and startDate < '2005-10-01'
--WHERE startDate > '2005-01-01' and endDate < '2005-10-01'
--WHERE endDate > '2005-01-01' and endDate < '2005-10-01'
--WHERE endDate > '2005-01-01' and startDate < '2005-10-01'
--WHERE (startDate > '2005-01-01' and startDate < '2005-10-01' ) OR (endDate > '2005-01-01' and endDate < '2005-10-01')
--WHERE (startDate > '2005-01-01' and startDate < '2005-10-01' ) AND (endDate > '2005-01-01' and endDate < '2005-10-01')