MYSQL SQLSTATE[42000] : Syntax error or access violation: 1064

标签 mysql laravel innodb

我有代码但没有本地主机,一个我无法理解的错误帮助 MYSQL 5.7.21 创新数据库 代码:

$sql = DB::select('
            SELECT 
                (case when (CAST(to as time) <= CAST("'.$time.'" as time) and 
                            CAST(do as time) >= CAST("'.$time.'" as time) or 
                            (to is null and do is null)) 
                             THEN
                                  1 
                             ELSE
                                  0 
                             END) as working
            FROM 
                franchises
    ');

错误:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an 
error in your SQL syntax; check the manual that corresponds to your 
MySQL server version for the right syntax to use near 'to as time) <= 
CAST("10:15" as time) and CAST(do as time) >= CAST("10:15" as tim' at
line 2 (SQL:

最佳答案

Toreserved word在 MySQL 中,因此您需要将其包含在反引号中:

...case when (CAST(`to` as time)...

关于MYSQL SQLSTATE[42000] : Syntax error or access violation: 1064,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52644347/

相关文章:

php - 如何在 select-option 标签中显示 mysql 数据库中的值

mysql - SQL 检查记录之一是否不存在并加入其他表

mysql - Docker MySQL无法连接到套接字

MySQL 关系和连接

java - Mysql - JPA 没有插入第三个表多对多

Laravel 删除belongsToMany 关系中的所有belongsToMany 关系

Laravel Eloquent select 函数导致空关系

php - 如何更改或管理 "Carbon"时区,使其不会来回移动时钟

mysql - InnoDB导致无法重启MySQL

mysql - SQL 从多个表中选择返回可用的内容