0

有人可以告诉我这段代码有什么问题导致它吐回错误吗?

我的代码如下:

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 服务器版本相对应的手册,以在第 3 行的“FROM training JOIN clients ON clients.client_id = training.train_clientid JOIN”附近使用正确的语法

我正在运行 phpmyadmin 版本信息:3.5.2.2

我之前用不同的值使用过这个脚本,没有问题

4

1 回答 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
于 2013-04-23T01:55:50.850 回答