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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 15:29:58  来源:igfitidea点击:

How to use greater than operator with date?

mysqldateoperators

提问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_datewith single quote causing it to become string, use backtickinstead

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';

回答by Suresh Kerai

I have tried but above not working after research found below the solution.

我已经尝试过,但在解决方案下方的研究中发现以上不起作用。

SELECT * FROM my_table where DATE(start_date) > '2011-01-01';

Ref

参考