1

So I have just upgraded to MySQL 8 to test if it would be a viable option, but I have stumbled upon quiet the riddle.

It throws an error at 'table_product_features AS pf' but I can't seem to figure out why as in the documentation it is done exactly the same way: https://dev.mysql.com/doc/refman/8.0/en/join.html

Error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'groups ON pf.parent_id = groups.feature_id LEFT JOIN table_product_features_des' at line 1 (1064)

I also checked the bug tracker but that doesnt seem to have anything related to my issue.

What exactly am I doing wrong here?

P.S. I put it in a code snippet so that it would remain formatted.

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 
4

1 回答 1

1

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

groups就是一个保留字,改成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 
于 2018-05-02T12:58:38.673 回答