mysql - #1064 - 创建 View 时 SQL 语法有错误

标签 mysql sql view

这段代码有什么问题导致它返回错误?

我的代码如下:

CREATE OR REPLACE VIEW vw_training AS 
SELECT training.train_attended, clients.client_firstname, clients.client_lastname, clients.client_swn, clients.client_id, locations.loc_id, locations.loc_title, locationsp.loc_id, locationsp.loc_title, 
FROM training 
JOIN clients ON clients.client_id = training.train_clientid
JOIN locations AS locationsp ON locations.loc_id = training.train_pickup
LEFT JOIN locations ON locations.loc_id = clients.client_winz

这是我返回的错误:

#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 'FROM training JOIN clients ON clients.client_id = training.train_clientid JOIN' at line 3

我正在运行 phpMyAdmin 版本 3.5.2.2。

我之前使用过具有不同值的此脚本,没有出现任何问题。

最佳答案

FROM 子句之前有一个额外的尾随逗号

SELECT ....,
       locationsp.loc_id, 
       locationsp.loc_title, -- <<== remove this trailing comma
FROM   training ...

另一个错误会引发此消息:“on Clause”中的未知列“locations.loc_id”是使用表名而不是提供的别名。应该是这样的,

JOIN locations AS locationsp ON locationsp.loc_id = training.train_pickup
                                    ^^ should use alias here

关于mysql - #1064 - 创建 View 时 SQL 语法有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16159596/

相关文章:

mysql - 从多个表中选择与 JOIN 比较

android - 遍历布局中的 View 并更改字体

python - 如何将 pandas DataFrame 中的 2 行与连续时间戳合并?

Java Jdbctemplate 查询具有命名参数和行映射器的列表?

sql - 有没有办法从时间戳类型列获取 DateTime 值?

sql - WHEN_VALIDATE 触发器中的 GO_BLOCK

ios - 推送到下一个vc。 wkWebView

image - 无法在 Yii 中显示图像

java - 如何在xml中映射@Field

sql - 通过 hiveql 添加组 id