Как мне решить эту ошибку синтаксиса sql?рядом (pl.name, '', CASE, КОГДА pal.name не имеет значение THEN GROUP_CONCAT (DISTINCT (pal.nam ' - PullRequest
0 голосов
/ 31 января 2019

Очевидно, у меня есть синтаксическая ошибка, которую я не получаю, вы могли бы мне помочь?

SELECT p.id_product, pa.ean13,pa.upc,p.active, p.isBike, p.isDirect, p.weight,p.height, p.width, p.depth, pa.reference, pl.description_short, pa.upc, p.price, pai.id_image CONCAT(pl.name, \' \', CASE WHEN pal.name is not null THEN GROUP_CONCAT(DISTINCT(pal.name) SEPARATOR ", ") ELSE "" END) as name
        FROM ps_product p
        LEFT JOIN ps_product_lang pl ON (p.id_product = pl.id_product)
        LEFT JOIN ps_product_attribute pa ON (p.id_product = pa.id_product)
        LEFT JOIN ps_product_attribute_combination pac ON (pac.id_product_attribute = pa.id_product_attribute)
        LEFT JOIN ps_attribute_lang pal ON (pal.id_attribute = pac.id_attribute)
        LEFT JOIN ps_stock_available s ON (p.id_product = s.id_product)
        WHERE pl.id_lang = 1
        AND p.id_shop_default = 1
        AND pl.name LIKE "%PRODUCT NAME%"
        GROUP BY pac.id_product_attribute
        ORDER BY pl.name
        LIMIT 60'

1 Ответ

0 голосов
/ 26 марта 2019

Помимо пропущенной запятой в операторе SELECT, вы также пропустили LEFT JOIN в таблице ps_product_attribute_image, вот правильный запрос SQL:

SELECT p.id_product, pa.ean13, pa.upc, p.active, p.isBike, p.isDirect, p.weight, p.height, p.width, p.depth, pa.reference, pl.description_short, pa.upc, p.price, pai.id_image,
CONCAT(pl.name, ' ', CASE WHEN pal.name is not null THEN GROUP_CONCAT(DISTINCT(pal.name) SEPARATOR ', ') ELSE '' END) as name
FROM ps_product p
LEFT JOIN ps_product_lang pl ON (p.id_product = pl.id_product)
LEFT JOIN ps_product_attribute pa ON (p.id_product = pa.id_product)
LEFT JOIN ps_product_attribute_combination pac ON (pac.id_product_attribute = pa.id_product_attribute)
LEFT JOIN ps_product_attribute_image pai ON (pai.id_product_attribute = pa.id_product_attribute)
LEFT JOIN ps_attribute_lang pal ON (pal.id_attribute = pac.id_attribute)
LEFT JOIN ps_stock_available s ON (p.id_product = s.id_product)
WHERE pl.id_lang = 1
AND p.id_shop_default = 1
AND pl.name LIKE '%PRODUCT NAME%'
GROUP BY pac.id_product_attribute
ORDER BY pl.name
LIMIT 60
...