Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.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_Datetime_Casting - Fatal编程技术网

如何将当前时间与MySQL中的时间变量进行比较

如何将当前时间与MySQL中的时间变量进行比较,mysql,datetime,casting,Mysql,Datetime,Casting,我需要编写一个查询,将当前时间与包含一些时间的变量进行比较 SQL查询: select time >= curtime() from appointment; 这里time是有一定时间的变量 这就是我得到的错误: Illegal mix of collations (utf8_general_ci,IMPLICIT) and (latin1_swedish_ci,NUMERIC) for operation '>='; nested exception is java.sql.SQ

我需要编写一个查询,将当前时间与包含一些时间的变量进行比较

SQL查询:

select time >= curtime() from appointment;
这里
time
是有一定时间的变量

这就是我得到的错误:

Illegal mix of collations (utf8_general_ci,IMPLICIT) and (latin1_swedish_ci,NUMERIC) for operation '>='; nested exception is java.sql.SQLException: Illegal mix of collations (utf8_general_ci,IMPLICIT) and (latin1_swedish_ci,NUMERIC) for operation '>='

我已经尝试过使用time(now()),但它不起作用。

约会。time
日期时间
或类似的数据类型,还是字符串

如果是
日期时间
时间戳
,而不是字符串,可能对系统的完整性最好

无论如何,试试这个

select CAST(time AS DATETIME) >= CURTIME()

您编写表达式的方式可能依赖于某种自动类型强制,最好将其显式化。

它可以正常工作,但对这个
select CAST(time AS time)>=CURTIME()
,因为我只需要时间。