2013-12-05 3 views
0

Я очень новичок в comlex SQL-запросах. Таким образом, я пытаюсь отлаживать SQL заявление, порожденного Magento:MySQL - # 1054 - Неизвестный столбец 'childs' в 'on clause'

SELECT `e`.*, 
     `cat_index`.`position`           AS 
     `cat_index_position`, 
     price_index.price             AS 
     `indexed_price`, 
     `price_index`.`price`, 
     `price_index`.`final_price`, 
     IF(`price_index`.`tier_price`, Least(`price_index`.`min_price`, 
              `price_index`.`tier_price`), 
     `price_index`.`min_price`)          AS 
     `minimal_price`, 
     `price_index`.`min_price`, 
     `price_index`.`max_price`, 
     `price_index`.`tier_price`, 
     GROUP_CONCAT(CONVERT(catalog_product_relation.child_id, CHAR(8))) AS 
     `children`, 
     `sfoi`.`price`             AS 
     `confprice` 
FROM `catalog_product_entity` AS `e` 
     INNER JOIN `catalog_category_product_index` AS `cat_index` 
       ON cat_index.product_id = e.entity_id 
        AND cat_index.store_id = 1 
        AND cat_index.visibility IN(2, 4) 
        AND cat_index.category_id = '3' 
     INNER JOIN `catalog_product_index_price` AS `price_index` 
       ON price_index.entity_id = e.entity_id 
        AND price_index.website_id = '1' 
        AND price_index.customer_group_id = 0 
     INNER JOIN `catalog_product_index_eav` AS `attributeA` 
       ON attributeA.entity_id = e.entity_id 
        AND attributeA.attribute_id = '184' 
        AND attributeA.store_id = '1' 
        AND attributeA.value IN (50) 
     INNER JOIN `catalog_product_index_eav` AS `attributeB` 
       ON attributeB.entity_id = e.entity_id 
        AND attributeB.attribute_id = '185' 
        AND attributeB.store_id = '1' 
        AND attributeB.value IN (95) 
     LEFT JOIN `catalog_product_relation` 
       ON e.entity_id = catalog_product_relation.parent_id 
     LEFT JOIN `catalog_product_flat_1` AS `sfoi` 
       ON sfoi.entity_id = `children` 
GROUP BY `e`.`entity_id` 
ORDER BY `confprice` DESC 
LIMIT 9 

Все отлично работает до тех пор:

LEFT JOIN `catalog_product_flat_1` AS `sfoi` 
     ON sfoi.entity_id = `children` 

я получаю следующее сообщение об ошибке:

#1054 - Unknown column 'children' in 'on clause' 

Я видел smilar но я не могу понять это сам. Пожалуйста, помогите мне.

EDIT:

PHP код, который генерирует запрос:

$this->_collection->getSelect()-> 
    joinLeft(
     'catalog_product_relation', 
     'e.entity_id = catalog_product_relation.parent_id', 
     'GROUP_CONCAT(CONVERT(catalog_product_relation.child_id, CHAR(8))) as children' 
); 
$this->_collection->getSelect()->joinLeft('catalog_product_flat_1 AS sfoi', 
    'sfoi.entity_id = children', 
    'sfoi.price AS confprice' 
)->order('confprice desc'); 

На самом деле, я пытаюсь соединить две таблицы (catalog_product_relation и catalog_product_flat_1). Но я не могу получить доступ к столбцу «дети» после присоединения к первой таблице.

+0

Ошибка не соответствует запросу. В вашем запросе нет «childs». –

+0

@juergen d, извините, что это была опечатка. – Tyui

+0

Можете ли вы опубликовать код, генерирующий этот запрос? – Marius

ответ

0

Добавьте соответствующий столбец в таблицу детей в состоянии ВКЛ.

ON sfoi.entity_id = catalog_product_relation.child_id 
+0

Это работает! Большое спасибо! – Tyui

Смежные вопросы