0

我需要从 mysql 数据库中获取显示的数据。我认为下面的代码展示了我正在尝试做的事情,但执行肯定是错误的。我需要改变什么才能让它工作?

SELECT 
up.model AS style,
up.list_price AS price,
GROUP_CONCAT(t1.name) AS colorlist,
GROUP_CONCAT(t2.name) AS sizelist,
nr.title,
nr.body AS description,
FROM 
uc_products up,
(SELECT c.name FROM uc_attributes a 
       JOIN uc_product_options b ON (b.nid = a.nid) 
       JOIN uc_attribute_options c ON (c.oid = b.oid AND c.aid = 6) 
       WHERE a.nid = up.nid) AS t1,
(SELECT c.name FROM uc_attributes a 
       JOIN uc_product_options b ON (b.nid = a.nid) 
       JOIN uc_attribute_options c ON (c.oid = b.oid AND c.aid = 9) 
       WHERE a.nid = up.nid) AS t2
LEFT JOIN node_revisions nr ON (nr.nid = up.nid)

错误:

#1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在“FROM uc_products up, (SELECT c.name FROM uc_attributes a JOIN uc_product_options) 附近使用正确的语法在第 8 行

4

2 回答 2

0

我认为问题在于逗号之前FROM。尝试这个:

SELECT 
up.model AS style,
up.list_price AS price,
GROUP_CONCAT(t1.name) AS colorlist,
GROUP_CONCAT(t2.name) AS sizelist,
nr.title,
nr.body AS description
FROM 
uc_products up,
(SELECT c.name FROM uc_attributes a JOIN uc_product_options b ON (b.nid = a.nid) JOIN uc_attribute_options c ON (c.oid = b.oid AND c.aid = 6) WHERE a.nid = up.nid) AS t1,
(SELECT c.name FROM uc_attributes a JOIN uc_product_options b ON (b.nid = a.nid) JOIN uc_attribute_options c ON (c.oid = b.oid AND c.aid = 9) WHERE a.nid = up.nid) AS t2
LEFT JOIN node_revisions nr ON (nr.nid = up.nid)
于 2013-08-06T20:15:40.207 回答
0

在“AS 描述”之后有一个额外的逗号需要删除。

于 2013-08-06T20:16:49.977 回答