gpt4 book ai didi

mysql - magento 集合上的条件 joinLeft

转载 作者:行者123 更新时间:2023-12-01 00:44:43 25 4
gpt4 key购买 nike

我的SQL查询语句如下:

SELECT * FROM `sales_flat_order_grid` AS `main_table` 
LEFT JOIN (SELECT * from `customer_address_entity_varchar`
WHERE attribute_id=31) AS `ce3`
ON main_table.customer_id=ce3.entity_id

我需要将其翻译成 Magento 风格。我试过了

$collection = Mage::getResourceModel('sales/order_grid_collection'); 
$tel = Mage::getModel('eav/entity_attribute')->loadByCode('2', 'telephone');

$collection->getSelect()
->joinLeft(array('ce3' => 'customer_address_entity_varchar'), 'main_table.customer_id=ce3.entity_id', array('telephone' => 'value'))
->where('ce3.attribute_id='.$tel->getAttributeId())

但这不起作用,因为在连接后应用了 where 语句,导致查询总数小于 sales_flat_order_grid。

最佳答案

我相信这可以解决您的问题:

 $collection -> getSelect() -> joinLeft(array("oauth"=>'customer_entity_varchar'), 
'main_table.customer_id=oauth.entity_id and oauth.attribute_id = 156',
array('OauthProvider' => "value"));

关于mysql - magento 集合上的条件 joinLeft,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23988873/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com