这是RECORDS
MySQL 表:
ID - BIGINT(20)
DATE - DATE
记录:
ID Date
1 2014-03-01
2 2014-03-02
3 2014-04-01
4 2014-04-02
这是第一个查询:
SELECT id, DATE_FORMAT(date,'%d/%m/%Y') AS date FROM records
WHERE
date >= STR_TO_DATE('01/04/2014','%d/%m/%Y') AND
date <= STR_TO_DATE('30/04/2014','%d/%m/%Y')
一切正常,我得到了结果:
3,2014-04-01
4,2014-04-02
但是,当我尝试使用这样的子查询获取日期范围时:
SELECT *
FROM (SELECT id, DATE_FORMAT(date,'%d/%m/%Y') AS date
FROM records) AS TEST
WHERE
date >= STR_TO_DATE('01/04/2014','%d/%m/%Y') AND
date <= STR_TO_DATE('30/04/2014','%d/%m/%Y')
我得到一个空的结果集(即零行)。
我的错误在哪里?