SQL查询失败,不明白为什么

时间:2018-05-02 12:47:59

标签: sql mysql-8.0

所以我刚刚升级到MySQL 8以测试它是否是一个可行的选择,但我偶然发现了这个谜语。

它会在&table; product_product_features AS pf'但我似乎无法弄清楚为什么在文档中它完全以相同的方式完成:https://dev.mysql.com/doc/refman/8.0/en/join.html

错误:

  

您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以获得正确的语法,以便在组附近使用ON pf.parent_id = groups.feature_id LEFT JOIN table_product_features_des'在第1行(1064)

我还检查了错误跟踪器,但似乎没有任何与我的问题相关的内容。

我到底错在了什么?

P.S。我把它放在一个代码片段中,以便它保持格式化。

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 

1 个答案:

答案 0 :(得分:1)

如果你没有使用聚合函数,我不明白为什么你需要GROUP BY

Also groups is a reserved word,将其更改为tgroups或其他内容。

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, 
       tdesc.description, 
       tdesc.lang_code, 
       tdesc.prefix, 
       tdesc.suffix, 
       pf.categories_path, 
       tdesc.full_description, 
       pf.status, 
       pf.comparison, 
       pf.position, 
       tgroups.position group_position, 
       tvals.value, 
       tvals.variant_id, 
       tvals.value_int 
FROM   table_product_features pf 
       LEFT JOIN table_product_features tgroups ON pf.parent_id = tgroups.feature_id 
       LEFT JOIN table_product_features_descriptions tdesc ON tdesc.feature_id = pf.feature_id AND tdesc.lang_code = 'en' 
       INNER JOIN table_product_features_values tvals ON tvals.feature_id = pf.feature_id AND tvals.product_id = 230 AND tvals.lang_code = 'en' 
       INNER JOIN table_ult_objects_sharing tshar ON (tshar.share_object_id = pf.feature_id AND tshar.share_company_id = 1 AND tshar.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)) 
ORDER BY group_position, pf.position, tdesc.description