#1064 - 创建视图时您的 SQL 语法有错误

问题描述 投票:0回答:1

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

我的代码如下:

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
- 你的 SQL 语法有错误;检查手册 对应于您的 MySQL 服务器版本,以便使用正确的语法 近 '来自培训加入客户 ON clients.client_id = training.train_clientid JOIN' 在第 3 行

我正在运行 phpMyAdmin 版本 3.5.2.2.

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

mysql sql view
1个回答
1
投票

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

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

和另一个会引发此消息的错误:

Unknown column 'locations.loc_id' in 'on clause'
是使用
tablename
而不是提供的别名。应该是,

JOIN locations AS locationsp ON locationsp.loc_id = training.train_pickup
                                    ^^ should use alias here
© www.soinside.com 2019 - 2024. All rights reserved.