SQL-запрос не выполняется, понятия не имею, почему - PullRequest
0 голосов
/ 02 мая 2018

Итак, я только что обновился до MySQL 8, чтобы проверить, будет ли это приемлемым вариантом, но я наткнулся на тихую загадку.

Выдает ошибку в table_product_features AS pf, но я не могу понять, почему, как в документации, это делается точно так же: https://dev.mysql.com/doc/refman/8.0/en/join.html

Ошибка:

В вашем синтаксисе SQL есть ошибка; проверьте руководство, соответствующее вашей версии сервера MySQL, чтобы найти правильный синтаксис для использования рядом с 'groups 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 голосов
/ 02 мая 2018

Если вы не используете агрегатные функции, я не понимаю, зачем вам нужен 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 
...