开发者

Why doesn't this query select any rows

What is wrong with this SQL?

It seems like it should work, but it doesn't.

utc_time is a datetime field.

SELECT id
FROM `foo`
WHERE utc_time > now() 
AND utc_time <= DATE_ADD(curdate(),INTERVAL 24 day);

Explain says that the Where clause i开发者_如何学Pythons impossible.

utc_time is type datetime. Here is a sample utc_time value: 2011-06-21 00:45:00


utc_time() is a built-in function. Even without the brackets, utc_time still returns the current UTC time.

Escape the column named utc_time. This works (I tested it):

SELECT id
FROM `foo`
WHERE `utc_time` > now() 
AND `utc_time` <= DATE_ADD(curdate(),INTERVAL 24 day);

Yet another example of why it's a bad idea to use reserved words or function names as column/table names.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜