我需要编写一个查询,我应该将当前时间与包含一些时间的变量进行比较。
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()) 但它不起作用。
最佳答案
appointment.time
是 DATETIME
或类似的数据类型,还是字符串?
如果它是 DATETIME
或 TIMESTAMP
而不是字符串,这可能最有利于您的系统完整性。
无论如何试试这个
select CAST(time AS DATETIME) >= CURTIME()
您编写表达式的方式可能依赖于某种自动类型强制转换,最好将其显式化。
关于mysql - 如何将当前时间与 MySQL 中的时间变量进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45032130/