Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql日期比较中的问题_Mysql_Sql_String_Datetime_Where Clause - Fatal编程技术网

Mysql日期比较中的问题

Mysql日期比较中的问题,mysql,sql,string,datetime,where-clause,Mysql,Sql,String,Datetime,Where Clause,我有一个表,它有一个datetime列,如下所示: --------------------- | date_time_column | --------------------- | 2020-09-14 14:00:13 | | 2020-05-18 14:00:13 | | 2021-12-14 14:00:13 | --------------------- 当我提出这些问题时 select * from `table` where TIMESTAMP('

我有一个表,它有一个datetime列,如下所示:

 ---------------------
|   date_time_column  |
 ---------------------
| 2020-09-14 14:00:13 |
| 2020-05-18 14:00:13 |
| 2021-12-14 14:00:13 |
 ---------------------
当我提出这些问题时

select * from `table` 
        where TIMESTAMP('date_time_column') < '2020-12-14 10:20:04' 
但是结果是什么也没有

您正在将文本字符串“date\u time\u column”转换为时间戳,而不是实际的列。因为这个字符串显然不是有效的时间戳,所以会得到一个空结果,它会过滤掉所有行

select timestamp('date_time_column') as res
您希望使用反勾号而不是单引号,如下所示:

select * 
from `table` 
where timestamp(`date_time_column`) < '2020-12-14 10:20:04' 
不引用标识符也很好:

where timestamp(date_time_column) < '2020-12-14 10:20:04' 
总之,时间戳转换没有任何好处,会减慢查询速度。只需执行直接过滤:

where date_time_column < '2020-12-14 10:20:04' 

这只是因为您的客户机在值的某些毫秒部分没有显示完整分辨率。因此,它们中没有一个与您请求的时间完全相等。尝试获取10:20:04和10:20:05之间的时间。您希望从该查询返回什么?如果您在where条件下使用full datetime,则无需使用时间戳,只需使用此select*from table where date_time_列<'2020-12-14 10:20:04';'日期\时间\列'是一个字符串。也许你在想“日期时间栏”,你试过调试你的查询吗?从表中选择*,时间戳'date\u time\u column'产生什么?另外,您能为您的表共享模式吗?问题是,我以前做过这些查询,当它在本地工作但不工作时,返回no rawserver@AbdullahAl_Nahhal例如我不知道你在说什么。答案解释了单引号而不是反勾号的问题,并解释了如何解决它。你试过建议的解决方案了吗?
where date_time_column < '2020-12-14 10:20:04'