如何使用大于运算符与日期?

时间:2022-11-22 02:35:00

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赛季开始的记录。到底发生了什么事?

3 个解决方案

#1


129  

you have enlosed start_date with single quote causing it to become string, use backtick instead

您已经将start_date用单引号括起来,导致它变成字符串,使用反勾代替

SELECT * FROM `la_schedule` WHERE `start_date` > '2012-11-18';

#2


17  

In your statement, you are comparing a string called start_date with the time.
If start_date is 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.

(引号)。希望这个有帮助。

#3


7  

Try this.

试试这个。

SELECT * FROM la_schedule WHERE `start_date` > '2012-11-18';

#1


129  

you have enlosed start_date with single quote causing it to become string, use backtick instead

您已经将start_date用单引号括起来,导致它变成字符串,使用反勾代替

SELECT * FROM `la_schedule` WHERE `start_date` > '2012-11-18';

#2


17  

In your statement, you are comparing a string called start_date with the time.
If start_date is 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.

(引号)。希望这个有帮助。

#3


7  

Try this.

试试这个。

SELECT * FROM la_schedule WHERE `start_date` > '2012-11-18';