这些结果有何意义?我不明白。
不应该例如最后一个查询返回一个空集,因为没有日期> 2010
的线程?为什么从2003年返回结果?
mysql> SELECT *
FROM thread
WHERE newsgroup_id = '64654'
AND 'thread_date' < '2010-09-10 21:43:05'
LIMIT 1;
空集(0.00秒)
mysql> SELECT *
FROM thread
WHERE newsgroup_id = '64654'
AND 'thread_date' < '2000-09-10 21:43:05'
LIMIT 1;
空集(0.00秒)
mysql> SELECT *
FROM thread
WHERE newsgroup_id = '64654'
AND 'thread_date' > '2000-09-10 21:43:05'
LIMIT 1;
+--------------+-----------+-----------+----------+---------------------+---------------------+---------------------------------+-------------------------+
| newsgroup_id | thread_id | postcount | hash | thread_date | thread_date_last | thread_title | title_has_valid_charset |
+--------------+-----------+-----------+----------+---------------------+---------------------+---------------------------------+-------------------------+
| 64654 | 1 | 0 | O2gvcPRl | 2003-06-06 22:51:24 | 0000-00-00 00:00:00 | Vendo fotodigit 2.1 megapixel | 0 |
+--------------+-----------+-----------+----------+---------------------+---------------------+---------------------------------+-------------------------+
1行(0.00秒)
mysql> SELECT *
FROM thread
WHERE newsgroup_id = '64654'
AND 'thread_date' > '2010-09-10 21:43:05'
LIMIT 1;
+--------------+-----------+-----------+----------+---------------------+---------------------+---------------------------------+-------------------------+
| newsgroup_id | thread_id | postcount | hash | thread_date | thread_date_last | thread_title | title_has_valid_charset |
+--------------+-----------+-----------+----------+---------------------+---------------------+---------------------------------+-------------------------+
| 64654 | 1 | 0 | O2gvcPRl | 2003-06-06 22:51:24 | 0000-00-00 00:00:00 | Vendo fotodigit 2.1 megapixel | 0 |
+--------------+-----------+-----------+----------+---------------------+---------------------+---------------------------------+-------------------------+
1行(0.00秒)
答案 0 :(得分:7)
您使用了错误的报价类型。 MySQL认为你正在比较字符串“thread_date”。这是应该如何:
`thread_date` > '2010-09-10 21:43:05'
这样MySQL知道你的意思是字段thread_date
并将其与表达式右侧的日期进行比较。
答案 1 :(得分:0)
'thread_date'
是一个字符串,而不是该字段的值。
你的意思是:
`thread_date` > '2010-09-10 21:43:05'