MySQL 如何在日期中使用大于运算符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13448340/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use greater than operator with date?
提问by Clinton J
No idea what is going on here. Here is the query, right from phpMyAdmin:
不知道这里发生了什么。这是来自 phpMyAdmin 的查询:
SELECT * FROM `la_schedule` WHERE 'start_date' >'2012-11-18';
But I consistently get all records in the table returned, including those with start date 2012-11-01. What gives?
但是我始终返回表中的所有记录,包括开始日期为 2012-11-01 的记录。是什么赋予了?
回答by John Woo
you have enlosed start_date
with single quote causing it to become string, use backtick
instead
你start_date
用单引号括起来导致它变成字符串,backtick
改用
SELECT * FROM `la_schedule` WHERE `start_date` > '2012-11-18';
回答by Kneel-Before-ZOD
In your statement, you are comparing a string called start_datewith the time.
If start_dateis a column, it should either be
在您的语句中,您将一个名为start_date的字符串与时间进行比较。
如果start_date是一列,它应该是
SELECT * FROM `la_schedule` WHERE start_date >'2012-11-18';
(no apostrophe) or
(无撇号)或
SELECT * FROM `la_schedule` WHERE `start_date` >'2012-11-18';
(with backticks).
Hope this helps.
(带反引号)。
希望这可以帮助。
回答by Faizan Khattak
Try this.
尝试这个。
SELECT * FROM la_schedule WHERE `start_date` > '2012-11-18';
回答by beatusfk
In my case my column was a datetime it kept giving me all records. What I did is to include time, see below example
在我的情况下,我的专栏是一个日期时间,它一直为我提供所有记录。我所做的是包括时间,见下面的例子
SELECT * FROM my_table where start_date > '2011-01-01 01:01:01';