【发布时间】:2018-05-02 12:47:58
【问题描述】:
所以我刚刚升级到 MySQL 8 来测试它是否是一个可行的选择,但我偶然发现了这个谜题。
它在“table_product_features AS pf”处引发错误,但我似乎无法弄清楚为什么在文档中它以完全相同的方式完成:https://dev.mysql.com/doc/refman/8.0/en/join.html
错误:
您的 SQL 语法有错误;查看与您的 MySQL 服务器版本相对应的手册,以在第 1 行 (1064) 的“groups ON pf.parent_id = groups.feature_id LEFT JOIN table_product_features_des”附近使用正确的语法
我还检查了错误跟踪器,但这似乎与我的问题没有任何关系。
我到底做错了什么?
附:我把它放在一个代码 sn-p 中,这样它就会保持格式化。
SELECT pf.feature_id,
pf.company_id,
pf.feature_type,
pf.parent_id,
pf.display_on_product,
pf.display_on_catalog,
pf.display_on_header,
table_product_features_descriptions.description,
table_product_features_descriptions.lang_code,
table_product_features_descriptions.prefix,
table_product_features_descriptions.suffix,
pf.categories_path,
table_product_features_descriptions.full_description,
pf.status,
pf.comparison,
pf.position,
groups.position AS group_position,
table_product_features_values.value,
table_product_features_values.variant_id,
table_product_features_values.value_int
FROM table_product_features AS pf
LEFT JOIN table_product_features AS groups
ON pf.parent_id = groups.feature_id
LEFT JOIN table_product_features_descriptions
ON table_product_features_descriptions.feature_id = pf.feature_id
AND table_product_features_descriptions.lang_code = 'en'
INNER JOIN table_product_features_values
ON table_product_features_values.feature_id = pf.feature_id
AND table_product_features_values.product_id = 230
AND table_product_features_values.lang_code = 'en'
INNER JOIN table_ult_objects_sharing
ON ( table_ult_objects_sharing.share_object_id = pf.feature_id
AND table_ult_objects_sharing.share_company_id = 1
AND table_ult_objects_sharing.share_object_type =
'product_features' )
WHERE 1
AND pf.feature_type != 'G'
AND pf.status IN ( 'A' )
AND pf.display_on_product = 'Y'
AND ( pf.categories_path = ''
OR Isnull(pf.categories_path)
OR Find_in_set(203, pf.categories_path)
OR Find_in_set(215, pf.categories_path)
OR Find_in_set(216, pf.categories_path) )
GROUP BY pf.feature_id
ORDER BY group_position,
pf.position,
table_product_features_descriptions.description
【问题讨论】:
-
简化问题,看看stackoverflow.com/help/mcve。
-
您得到的确切错误是什么?
-
你的
group by不应该工作。将所有未聚合的列放在group by子句中。 -
@Matt 我在描述中添加了错误。