开发者

Why doesn't this query select any rows

开发者 https://www.devze.com 2023-03-12 16:44 出处:网络
What is wrong with this SQL? It seems like it should work, but it doesn\'t. utc_time is a datetime field.

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

精彩评论

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